mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 20:42:04 +00:00
add options support
This commit is contained in:
parent
82a849ba8e
commit
c8892ec7a7
@ -25,6 +25,7 @@
|
|||||||
#include <Server/HTTPHandlerFactory.h>
|
#include <Server/HTTPHandlerFactory.h>
|
||||||
#include <Server/HTTPHandlerRequestFilter.h>
|
#include <Server/HTTPHandlerRequestFilter.h>
|
||||||
#include <Server/IServer.h>
|
#include <Server/IServer.h>
|
||||||
|
#include "common/logger_useful.h"
|
||||||
#include <Common/SettingsChanges.h>
|
#include <Common/SettingsChanges.h>
|
||||||
#include <Common/StringUtils/StringUtils.h>
|
#include <Common/StringUtils/StringUtils.h>
|
||||||
#include <Common/escapeForFileName.h>
|
#include <Common/escapeForFileName.h>
|
||||||
@ -111,10 +112,11 @@ namespace ErrorCodes
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/// Process options request. Usefull for CORS.
|
/// Process options request. Useful for CORS.
|
||||||
void processOptionsRequest(HTTPServerResponse & response, const Poco::Util::LayeredConfiguration & config)
|
void processOptionsRequest(HTTPServerResponse & response, const Poco::Util::LayeredConfiguration & config)
|
||||||
{
|
{
|
||||||
/// If answer for options request was not defined, return 501 to client.
|
/// If response for options request was not defined, return 501 to client.
|
||||||
|
/// TODO should it be here?
|
||||||
if (!config.has("http_options_response"))
|
if (!config.has("http_options_response"))
|
||||||
{
|
{
|
||||||
response.setStatusAndReason(HTTPResponse::HTTP_NOT_IMPLEMENTED);
|
response.setStatusAndReason(HTTPResponse::HTTP_NOT_IMPLEMENTED);
|
||||||
@ -129,12 +131,17 @@ namespace
|
|||||||
{
|
{
|
||||||
if (config_key == "header" || config_key.starts_with("header["))
|
if (config_key == "header" || config_key.starts_with("header["))
|
||||||
{
|
{
|
||||||
response.add(config.getString("http_options_response." + config_key + ".name", "Empty header"),
|
/// If there is empty header name, it will not be processed and message about it will be in logs
|
||||||
config.getString("http_options_response." + config_key + ".value", ""));
|
if (config.getString("http_options_response." + config_key + ".name", "").empty())
|
||||||
response.setKeepAlive(false);
|
LOG_WARNING(&Poco::Logger::get("processOptionsRequest"), "Empty header was found in config. It will not be processed.");
|
||||||
|
else
|
||||||
|
response.add(config.getString("http_options_response." + config_key + ".name", ""),
|
||||||
|
config.getString("http_options_response." + config_key + ".value", ""));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.setStatusAndReason(HTTPResponse::HTTP_NO_CONTENT);
|
response.setKeepAlive(false);
|
||||||
|
response.setStatusAndReason(HTTPResponse::HTTP_OK);
|
||||||
response.send();
|
response.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ static inline HTTPRequestHandlerFactoryPtr createInterserverHTTPHandlerFactory(I
|
|||||||
addCommonDefaultHandlersFactory(*factory, server);
|
addCommonDefaultHandlersFactory(*factory, server);
|
||||||
|
|
||||||
auto main_handler = std::make_shared<HandlingRuleHTTPHandlerFactory<InterserverIOHTTPHandler>>(server);
|
auto main_handler = std::make_shared<HandlingRuleHTTPHandlerFactory<InterserverIOHTTPHandler>>(server);
|
||||||
main_handler->allowPostAndGetParamsRequest();
|
main_handler->allowPostAndGetParamsAndOptionsRequest();
|
||||||
factory->addHandler(main_handler);
|
factory->addHandler(main_handler);
|
||||||
|
|
||||||
return factory;
|
return factory;
|
||||||
@ -180,7 +180,7 @@ void addDefaultHandlersFactory(HTTPRequestHandlerFactoryMain & factory, IServer
|
|||||||
addCommonDefaultHandlersFactory(factory, server);
|
addCommonDefaultHandlersFactory(factory, server);
|
||||||
|
|
||||||
auto query_handler = std::make_shared<HandlingRuleHTTPHandlerFactory<DynamicQueryHandler>>(server, "query");
|
auto query_handler = std::make_shared<HandlingRuleHTTPHandlerFactory<DynamicQueryHandler>>(server, "query");
|
||||||
query_handler->allowPostAndGetParamsRequest();
|
query_handler->allowPostAndGetParamsAndOptionsRequest();
|
||||||
factory.addHandler(query_handler);
|
factory.addHandler(query_handler);
|
||||||
|
|
||||||
/// We check that prometheus handler will be served on current (default) port.
|
/// We check that prometheus handler will be served on current (default) port.
|
||||||
|
@ -104,11 +104,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handle POST or GET with params
|
/// Handle POST or GET with params
|
||||||
void allowPostAndGetParamsRequest()
|
void allowPostAndGetParamsAndOptionsRequest()
|
||||||
{
|
{
|
||||||
addFilter([](const auto & request)
|
addFilter([](const auto & request)
|
||||||
{
|
{
|
||||||
return request.getURI().find('?') != std::string::npos
|
return (request.getURI().find('?') != std::string::npos
|
||||||
|
&& request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
|
||||||
|
|| request.getMethod() == Poco::Net::HTTPRequest::HTTP_OPTIONS
|
||||||
|| request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST;
|
|| request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user