Initial commit
This commit is contained in:
37
src/http/response.cpp
Normal file
37
src/http/response.cpp
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user