MXS-1220: Expand HttpResponse class

The class now generates default headers. The ETag and Last-Modified tags
do not represent any actual modification time or resource hash.

The basic functionality of the HTTP responses is tested by the core test
suite. More advanced testing of the whole REST API is still required.

Removed the static `create` functions as only the JSON parsing version
could generated errors and even then the errors were unlikely. By
replacing the static creator function with a normal constructor, the
HttpResponse class can now also be created on the stack making its use
easier.
This commit is contained in:
Markus Mäkelä
2017-04-17 03:13:22 +03:00
committed by Markus Mäkelä
parent a73d3e9276
commit 9d0d394361
7 changed files with 114 additions and 42 deletions

View File

@ -34,12 +34,12 @@ class HttpResponse
{
public:
/**
* @brief Create a new HTTP response
*
* @param request Response body
*/
static HttpResponse* create(string response = "", enum http_code code = HTTP_200_OK);
static HttpResponse* create(json_t* response, enum http_code code = HTTP_200_OK);
* @brief Create new HTTP response
*
* @param response Response body
* @param code HTTP return code
*/
HttpResponse(string response = "", enum http_code code = HTTP_200_OK);
~HttpResponse();
@ -59,11 +59,10 @@ public:
string get_response() const;
private:
HttpResponse(string response, enum http_code code);
HttpResponse(const HttpResponse&);
HttpResponse& operator = (const HttpResponse&);
string m_body; /**< Message body */
map<string, string> m_headers; /**< Message headers */
http_code m_code; /**< The HTTP code for the response */
};
};