diff --git a/Documentation/REST-API/API.md b/Documentation/REST-API/API.md index 2bc7980df..8ad0bc5b5 100644 --- a/Documentation/REST-API/API.md +++ b/Documentation/REST-API/API.md @@ -159,10 +159,14 @@ The value of this header must be a date value in the #### X-HTTP-Method-Override Some clients only support GET and PUT requests. By providing the string value of -the intended method in the `X-HTTP-Method-Override` header, a client can perform -a POST, PATCH or DELETE request with the PUT method +the intended method in the `X-HTTP-Method-Override` header, a client can, for +example, perform a POST, PATCH or DELETE request with the PUT method (e.g. `X-HTTP-Method-Override: PATCH`). +If this header is defined in the request, the current method of the request is +replaced with the one in the header. The HTTP method must be in uppercase and it +must be one of the methods that the requested resource supports. + ### Response Headers #### Allow diff --git a/server/core/httprequest.cc b/server/core/httprequest.cc index 5027b5a3c..2611dcfc1 100644 --- a/server/core/httprequest.cc +++ b/server/core/httprequest.cc @@ -20,7 +20,8 @@ using std::string; using std::deque; -#define HTTP_HOST_HEADER "Host" +#define HTTP_HOST_HEADER "Host" +#define HTTP_METHOD_OVERRIDE "X-HTTP-Method-Override" const std::string HttpRequest::HTTP_PREFIX = "http://"; const std::string HttpRequest::HTTPS_PREFIX = "https://"; @@ -95,6 +96,13 @@ HttpRequest::HttpRequest(struct MHD_Connection *connection, string url, string m m_hostname = mxs_admin_https_enabled() ? HttpRequest::HTTPS_PREFIX : HttpRequest::HTTP_PREFIX; m_hostname += get_header(HTTP_HOST_HEADER); + string method_override = get_header(HTTP_METHOD_OVERRIDE); + + if (method_override.length()) + { + m_verb = method_override; + } + if (m_hostname[m_hostname.size() - 1] != '/') { m_hostname += "/";