mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
add options method
This commit is contained in:
parent
7246825d8d
commit
82a849ba8e
@ -62,6 +62,25 @@
|
||||
-->
|
||||
</logger>
|
||||
|
||||
<http_options_response>
|
||||
<header>
|
||||
<name>Access-Control-Allow-Origin</name>
|
||||
<value>*</value>
|
||||
</header>
|
||||
<header>
|
||||
<name>Access-Control-Allow-Headers</name>
|
||||
<value>origin, x-requested-with</value>
|
||||
</header>
|
||||
<header>
|
||||
<name>Access-Control-Allow-Methods</name>
|
||||
<value>POST, GET, OPTIONS</value>
|
||||
</header>
|
||||
<header>
|
||||
<name>Access-Control-Max-Age</name>
|
||||
<value>86400</value>
|
||||
</header>
|
||||
</http_options_response>
|
||||
|
||||
<!-- It is the name that will be shown in the clickhouse-client.
|
||||
By default, anything with "production" will be highlighted in red in query prompt.
|
||||
-->
|
||||
|
@ -35,8 +35,9 @@ public:
|
||||
enum class HTTPMethod : uint8_t
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
GET = 1,
|
||||
POST = 2,
|
||||
GET = 1,
|
||||
POST = 2,
|
||||
OPTIONS = 3
|
||||
};
|
||||
|
||||
enum class QueryKind : uint8_t
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <common/getFQDNOrHostName.h>
|
||||
#include <common/scope_guard.h>
|
||||
#include "Server/HTTP/HTTPResponse.h"
|
||||
|
||||
#if !defined(ARCADIA_BUILD)
|
||||
# include <Common/config.h>
|
||||
@ -108,6 +109,37 @@ namespace ErrorCodes
|
||||
extern const int HTTP_LENGTH_REQUIRED;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Process options request. Usefull for CORS.
|
||||
void processOptionsRequest(HTTPServerResponse & response, const Poco::Util::LayeredConfiguration & config)
|
||||
{
|
||||
/// If answer for options request was not defined, return 501 to client.
|
||||
if (!config.has("http_options_response"))
|
||||
{
|
||||
response.setStatusAndReason(HTTPResponse::HTTP_NOT_IMPLEMENTED);
|
||||
response.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
/// otherwise fill response.
|
||||
Strings config_keys;
|
||||
config.keys("http_options_response", config_keys);
|
||||
for (const std::string & config_key : config_keys)
|
||||
{
|
||||
if (config_key == "header" || config_key.starts_with("header["))
|
||||
{
|
||||
response.add(config.getString("http_options_response." + config_key + ".name", "Empty header"),
|
||||
config.getString("http_options_response." + config_key + ".value", ""));
|
||||
response.setKeepAlive(false);
|
||||
}
|
||||
}
|
||||
response.setStatusAndReason(HTTPResponse::HTTP_NO_CONTENT);
|
||||
response.send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String base64Decode(const String & encoded)
|
||||
{
|
||||
String decoded;
|
||||
@ -850,6 +882,11 @@ void HTTPHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
|
||||
|
||||
try
|
||||
{
|
||||
if (request.getMethod() == HTTPServerRequest::HTTP_OPTIONS)
|
||||
{
|
||||
processOptionsRequest(response, server.config());
|
||||
return;
|
||||
}
|
||||
response.setContentType("text/plain; charset=UTF-8");
|
||||
response.set("X-ClickHouse-Server-Display-Name", server_display_name);
|
||||
/// For keep-alive to work.
|
||||
|
Loading…
Reference in New Issue
Block a user