First really working router Version

This commit is contained in:
Pablu23
2024-07-08 16:08:10 +02:00
parent 752cb229c3
commit 986be64e03
12 changed files with 424 additions and 73 deletions

View File

@@ -7,13 +7,15 @@
#include <string>
#include <vector>
Response::Response(std::vector<std::byte> data) {
Response::Response(http::statusCode statusCode) { m_statusCode = statusCode; }
void Response::SetPayload(std::vector<std::byte> data) {
m_headers.insert(std::pair<std::string, std::string>(
"content-length", std::to_string(data.size())));
m_payload = data;
}
Response::Response(std::string data) {
void Response::SetPayload(std::string data) {
m_headers.insert(std::pair<std::string, std::string>(
"content-length", std::to_string(std::strlen(data.data()))));
@@ -28,7 +30,8 @@ void Response::SetContentType(const std::string type) {
void Response::Send(int clientSocket) {
std::stringstream ss;
ss << "HTTP/1.1 200 OK\n";
ss << "HTTP/1.1 " << m_statusCode << " "
<< http::StatusCodeString(m_statusCode) << "\n";
for (const auto &[key, value] : m_headers) {
ss << key << ": " << value << "\n";
}