MXS-1220: Move header generation back to HttpResponse

The actual list of headers is not known when the request is first
generated. This prevents the headers from being generated in admin.cc
which handles things on a lower level.

The moving of the header generation is done with the OPTIONS method in
mind. This header needs to be generated inside the RootResource class
which manages the navigation of the resources.
This commit is contained in:
Markus Mäkelä
2017-04-19 20:58:23 +03:00
committed by Markus Mäkelä
parent bc3cfe0221
commit c17c451fb5
5 changed files with 82 additions and 30 deletions

View File

@ -19,8 +19,6 @@
#include <maxscale/thread.h>
using std::string;
class Client
{
public:
@ -30,7 +28,7 @@ public:
*
* @param connection The connection handle for this client
*/
Client(struct MHD_Connection *connection):
Client(MHD_Connection *connection):
m_connection(connection)
{
}
@ -52,11 +50,11 @@ public:
*
* @return MHD_YES on success, MHD_NO on error
*/
int process(string url, string method, const char* data, size_t *size);
int process(std::string url, std::string method, const char* data, size_t *size);
private:
struct MHD_Connection* m_connection; /**< Connection handle */
string m_data; /**< Uploaded data */
MHD_Connection* m_connection; /**< Connection handle */
std::string m_data; /**< Uploaded data */
};
/**

View File

@ -119,7 +119,7 @@ public:
*
* @return Raw JSON body or NULL if no body is defined
*/
json_t* get_json()
json_t* get_json() const
{
return m_json.get();
}

View File

@ -23,6 +23,16 @@
#include "http.hh"
/**
* A list of default headers that are generated with each response
*/
#define HTTP_RESPONSE_HEADER_DATE "Date"
#define HTTP_RESPONSE_HEADER_LAST_MODIFIED "Last-Modified"
#define HTTP_RESPONSE_HEADER_ETAG "ETag"
#define HTTP_RESPONSE_HEADER_ACCEPT "Accept"
typedef std::map<std::string, std::string> Headers;
class HttpResponse
{
public:
@ -45,6 +55,13 @@ public:
*/
json_t* get_response() const;
/**
* @brief Drop response body
*
* This discards the message body.
*/
void drop_response();
/**
* @brief Get the HTTP response code
*
@ -52,7 +69,23 @@ public:
*/
int get_code() const;
/**
* @brief Add an extra header to this response
*
* @param key Header name
* @param value Header value
*/
void add_header(const std::string& key, const std::string& value);
/**
* @brief Get request headers
*
* @return Headers of this request
*/
const Headers& get_headers() const;
private:
json_t* m_body; /**< Message body */
int m_code; /**< The HTTP code for the response */
Headers m_headers; /**< Extra headers */
};