Files
http-server/src/http/response.cpp
2019-06-15 12:00:21 +02:00

37 lines
780 B
C++

#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()
{
}
}