
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.
92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
#pragma once
|
|
/*
|
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
|
*
|
|
* Use of this software is governed by the Business Source License included
|
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
*
|
|
* Change Date: 2019-07-01
|
|
*
|
|
* On the date above, in accordance with the Business Source License, use
|
|
* of this software will be governed by version 2 or later of the General
|
|
* Public License.
|
|
*/
|
|
|
|
#include <maxscale/cppdefs.hh>
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <tr1/memory>
|
|
#include <microhttpd.h>
|
|
|
|
#include <maxscale/jansson.hh>
|
|
|
|
#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:
|
|
/**
|
|
* @brief Create new HTTP response
|
|
*
|
|
* @param response Response body
|
|
* @param code HTTP return code
|
|
*/
|
|
HttpResponse(int code = MHD_HTTP_OK, json_t* response = NULL);
|
|
HttpResponse(const HttpResponse& response);
|
|
HttpResponse& operator = (const HttpResponse& response);
|
|
|
|
~HttpResponse();
|
|
|
|
/**
|
|
* @brief Get the response body
|
|
*
|
|
* @return The response body
|
|
*/
|
|
json_t* get_response() const;
|
|
|
|
/**
|
|
* @brief Drop response body
|
|
*
|
|
* This discards the message body.
|
|
*/
|
|
void drop_response();
|
|
|
|
/**
|
|
* @brief Get the HTTP response code
|
|
*
|
|
* @return The HTTP response code
|
|
*/
|
|
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 */
|
|
};
|