MXS-1220: Reorganize request and response processing

The standard response headers are now generated at a higher level. This
reduces the scope of the HttpResponse class making it a leaner wrapper
around a few simple variables, namely the JSON body of the response.

The HttpRequest now exposes the Host header that the client sent. This
allows resource relations to be real links that work without modification.
This commit is contained in:
Markus Mäkelä
2017-04-19 10:07:08 +03:00
committed by Markus Mäkelä
parent 8c77e62872
commit 52e075963e
5 changed files with 52 additions and 45 deletions

View File

@ -23,32 +23,35 @@
using std::string;
using std::stringstream;
HttpResponse::HttpResponse(int code, string response):
HttpResponse::HttpResponse(int code, json_t* response):
m_body(response),
m_code(code)
{
m_headers["Date"] = http_get_date();
}
// TODO: Add proper modification timestamps
m_headers["Last-Modified"] = m_headers["Date"];
// TODO: Add proper ETags
m_headers["ETag"] = "bm90LXlldC1pbXBsZW1lbnRlZAo=";
HttpResponse::HttpResponse(const HttpResponse& response):
m_body(response.m_body),
m_code(response.m_code)
{
json_incref(m_body);
}
HttpResponse& HttpResponse::operator=(const HttpResponse& response)
{
m_body = json_incref(response.m_body);
m_code = response.m_code;
return *this;
}
HttpResponse::~HttpResponse()
{
if (m_body)
{
json_decref(m_body);
}
}
void HttpResponse::add_header(string name, string value)
{
m_headers[name] = value;
}
const map<string, string>& HttpResponse::get_headers() const
{
return m_headers;
}
string HttpResponse::get_response() const
json_t* HttpResponse::get_response() const
{
return m_body;
}