Initial commit

This commit is contained in:
2019-06-15 12:00:21 +02:00
commit eda5d9df6b
31 changed files with 1328 additions and 0 deletions

37
src/http/response.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "response.hpp"
#include <sstream>
namespace Http
{
std::vector<char> Response::Serialize()
{
// TODO implement headers properly
std::stringstream ss;
ss << "HTTP/1.1";
ss << ' ' << HttpResponse::codeValues[static_cast<int>(code)];
ss << ' ' << HttpResponse::codeStrings[static_cast<int>(code)];
ss << "\r\n";
ss << "Server: http-server/0.1\r\n";
if (contentType.size() > 0)
{
ss << "Content-Type: ";
ss << contentType << "\r\n";
}
ss << "\r\n";
auto header = ss.str();
std::vector<char> buffer (header.begin(), header.end());
buffer.insert(buffer.end(), content.begin(), content.end());
return buffer;
}
Response::Response()
: code(HttpResponse::Code::UNKNOWN),
contentType(),
content()
{
}
}