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

@ -165,6 +165,10 @@ public:
return m_resource_parts.size();
}
const char* host() const
{
return m_hostname.c_str();
}
private:
map<string, string> m_options; /**< Request options */
@ -173,5 +177,6 @@ private:
string m_resource; /**< Requested resource */
deque<string> m_resource_parts; /**< @c m_resource split into parts */
string m_verb; /**< Request method */
string m_hostname; /**< The value of the Host header */
struct MHD_Connection* m_connection;
};

View File

@ -40,31 +40,18 @@ public:
* @param response Response body
* @param code HTTP return code
*/
HttpResponse(int code = MHD_HTTP_OK, string response = "");
HttpResponse(int code = MHD_HTTP_OK, json_t* response = NULL);
HttpResponse(const HttpResponse& response);
HttpResponse& operator = (const HttpResponse& response);
~HttpResponse();
/**
* @brief Add a header to the response
* @brief Get the response body
*
* @param name Header name
* @param value Header value
* @return The response body
*/
void add_header(string name, string value);
/**
* @brief Get headers for this response
*
* @return Map of headers and values
*/
const map<string, string>& get_headers() const;
/**
* @brief Get the response in string format
*
* @return The complete response that can be sent to a client
*/
string get_response() const;
json_t* get_response() const;
/**
* @brief Get the HTTP response code
@ -74,7 +61,6 @@ public:
int get_code() const;
private:
string m_body; /**< Message body */
map<string, string> m_headers; /**< Message headers */
int m_code; /**< The HTTP code for the response */
json_t* m_body; /**< Message body */
int m_code; /**< The HTTP code for the response */
};