mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #297 from proller/METR-23933
Add header Keep-Alive: timeout=.. to http server response [#METR-23933]
This commit is contained in:
commit
376db5785b
10
dbms/include/DB/IO/HTTPCommon.h
Normal file
10
dbms/include/DB/IO/HTTPCommon.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <Poco/Net/HTTPServerResponse.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
void setResponseDefaultHeaders(Poco::Net::HTTPServerResponse & response);
|
||||
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <DB/IO/WriteBuffer.h>
|
||||
#include <DB/IO/BufferWithOwnMemory.h>
|
||||
#include <DB/IO/HTTPCommon.h>
|
||||
#include <DB/Common/NetException.h>
|
||||
|
||||
|
||||
@ -53,6 +54,8 @@ private:
|
||||
response.set("Access-Control-Allow-Origin","*");
|
||||
}
|
||||
|
||||
setResponseDefaultHeaders(response);
|
||||
|
||||
if (compress && offset()) /// Пустой ответ сжимать не нужно.
|
||||
{
|
||||
if (compression_method == Poco::DeflatingStreamBuf::STREAM_GZIP)
|
||||
|
17
dbms/src/IO/HTTPCommon.cpp
Normal file
17
dbms/src/IO/HTTPCommon.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <DB/IO/HTTPCommon.h>
|
||||
|
||||
#include <Poco/Util/Application.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
void setResponseDefaultHeaders(Poco::Net::HTTPServerResponse & response) {
|
||||
if (!response.getKeepAlive())
|
||||
return;
|
||||
|
||||
Poco::Timespan keep_alive_timeout(Poco::Util::Application::instance().config().getInt("keep_alive_timeout", 10), 0);
|
||||
if (keep_alive_timeout.totalSeconds())
|
||||
response.set("Keep-Alive", "timeout=" + std::to_string(keep_alive_timeout.totalSeconds()));
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include <DB/Storages/StorageReplicatedMergeTree.h>
|
||||
#include <DB/Common/HTMLForm.h>
|
||||
#include <DB/Databases/IDatabase.h>
|
||||
#include <DB/IO/HTTPCommon.h>
|
||||
|
||||
#include <Poco/Net/HTTPServerRequest.h>
|
||||
#include <Poco/Net/HTTPServerResponse.h>
|
||||
@ -60,6 +61,8 @@ void ReplicasStatusHandler::handleRequest(Poco::Net::HTTPServerRequest & request
|
||||
}
|
||||
}
|
||||
|
||||
setResponseDefaultHeaders(response);
|
||||
|
||||
if (ok && !verbose)
|
||||
{
|
||||
const char * data = "Ok.\n";
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <DB/Common/Macros.h>
|
||||
#include <DB/Common/getFQDNOrHostName.h>
|
||||
#include <DB/Common/StringUtils.h>
|
||||
#include <DB/IO/HTTPCommon.h>
|
||||
|
||||
#include <DB/Interpreters/loadMetadata.h>
|
||||
#include <DB/Interpreters/ProcessList.h>
|
||||
@ -73,6 +74,7 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
setResponseDefaultHeaders(response);
|
||||
const char * data = "Ok.\n";
|
||||
response.sendBuffer(data, strlen(data));
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
< Connection: Keep-Alive
|
||||
< Keep-Alive: timeout=3
|
||||
< Connection: Keep-Alive
|
||||
< Keep-Alive: timeout=3
|
||||
< Connection: Keep-Alive
|
||||
< Keep-Alive: timeout=3
|
||||
< Connection: Keep-Alive
|
||||
< Keep-Alive: timeout=3
|
9
dbms/tests/queries/0_stateless/00408_http_keep_alive.sh
Executable file
9
dbms/tests/queries/0_stateless/00408_http_keep_alive.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
curl -vsS http://localhost:8123/ --data-binary @- <<< "SELECT 1" 2>&1 | perl -lnE 'print if /Keep-Alive/';
|
||||
curl -vsS http://localhost:8123/ --data-binary @- <<< " error here " 2>&1 | perl -lnE 'print if /Keep-Alive/';
|
||||
curl -vsS http://localhost:8123/ping 2>&1 | perl -lnE 'print if /Keep-Alive/';
|
||||
curl -vsS http://localhost:8123/replicas_status 2>&1 | perl -lnE 'print if /Keep-Alive/';
|
||||
|
||||
# no keep-alive:
|
||||
curl -vsS http://localhost:8123/404/not/found/ 2>&1 | perl -lnE 'print if /Keep-Alive/';
|
Loading…
Reference in New Issue
Block a user