Fix an error for POST queries with empty body. [#CLICKHOUSE-3333]

This commit is contained in:
Vitaliy Lyudvichenko 2017-09-24 02:32:26 +03:00 committed by alexey-milovidov
parent 70165b949f
commit 9d3f28f52d
3 changed files with 15 additions and 1 deletions

View File

@ -35,6 +35,8 @@
#include <Interpreters/Quota.h>
#include <Common/typeid_cast.h>
#include <Poco/Net/HTTPStream.h>
#include "HTTPHandler.h"
namespace DB
@ -377,7 +379,14 @@ void HTTPHandler::processQuery(
std::unique_ptr<ReadBuffer> in_param = std::make_unique<ReadBufferFromString>(query_param);
std::unique_ptr<ReadBuffer> in_post_raw = std::make_unique<ReadBufferFromIStream>(istr);
std::unique_ptr<ReadBuffer> in_post_raw;
/// A grubby workaround for CLICKHOUSE-3333 problem. This if should detect POST query with empty body.
/// In that case Poco doesn't work properly and returns HTTPInputStream which just listen TCP connection.
/// NOTE: if Poco are updated, this heuristic might not work properly.
if (dynamic_cast<Poco::Net::HTTPInputStream *>(&istr) == nullptr)
in_post_raw = std::make_unique<ReadBufferFromIStream>(istr);
else
in_post_raw = std::make_unique<ReadBufferFromString>(String()); // will read empty body.
/// Request body can be compressed using algorithm specified in the Content-Encoding header.
std::unique_ptr<ReadBuffer> in_post;

View File

@ -10,3 +10,5 @@ Content-Type: text/tab-separated-values; charset=UTF-8
Transfer-Encoding: chunked
Keep-Alive: timeout=3
1
1

View File

@ -2,3 +2,6 @@
( curl -s --head "${CLICKHOUSE_URL:=http://localhost:8123/}?query=SELECT%201";
curl -s --head "${CLICKHOUSE_URL:=http://localhost:8123/}?query=select+*+from+system.numbers+limit+1000000" ) | grep -v "Date:"
curl -sS -X POST "http://127.0.0.1:8123?query=SELECT+1"
curl -sS -X POST "http://127.0.0.1:8123?query=SELECT+1" --data ''