mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Segmentation fault on HEAD HTTP query #912
This commit is contained in:
parent
049569c102
commit
863fd72c8a
@ -30,7 +30,8 @@ void WriteBufferFromHTTPServerResponse::startSendHeaders()
|
||||
setResponseDefaultHeaders(response);
|
||||
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
std::tie(response_header_ostr, response_body_ostr) = response.beginSend();
|
||||
if (request.getMethod() != Poco::Net::HTTPRequest::HTTP_HEAD)
|
||||
std::tie(response_header_ostr, response_body_ostr) = response.beginSend();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -42,16 +43,21 @@ void WriteBufferFromHTTPServerResponse::finishSendHeaders()
|
||||
{
|
||||
headers_finished_sending = true;
|
||||
|
||||
if (request.getMethod() != Poco::Net::HTTPRequest::HTTP_HEAD) {
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
/// Send end of headers delimiter.
|
||||
if (response_header_ostr)
|
||||
*response_header_ostr << "\r\n" << std::flush;
|
||||
/// Send end of headers delimiter.
|
||||
if (response_header_ostr)
|
||||
*response_header_ostr << "\r\n" << std::flush;
|
||||
#else
|
||||
/// Newline autosent by response.send()
|
||||
/// if nothing to send in body:
|
||||
if (!response_body_ostr)
|
||||
response_body_ostr = &(response.send());
|
||||
/// Newline autosent by response.send()
|
||||
/// if nothing to send in body:
|
||||
if (!response_body_ostr)
|
||||
response_body_ostr = &(response.send());
|
||||
#endif
|
||||
} else {
|
||||
if (!response_body_ostr)
|
||||
response_body_ostr = &(response.send());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +69,7 @@ void WriteBufferFromHTTPServerResponse::nextImpl()
|
||||
|
||||
startSendHeaders();
|
||||
|
||||
if (!out)
|
||||
if (!out && request.getMethod() != Poco::Net::HTTPRequest::HTTP_HEAD)
|
||||
{
|
||||
if (compress)
|
||||
{
|
||||
@ -111,17 +117,20 @@ void WriteBufferFromHTTPServerResponse::nextImpl()
|
||||
|
||||
}
|
||||
|
||||
out->position() = position();
|
||||
out->next();
|
||||
if (out) {
|
||||
out->position() = position();
|
||||
out->next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WriteBufferFromHTTPServerResponse::WriteBufferFromHTTPServerResponse(
|
||||
Poco::Net::HTTPServerRequest & request_,
|
||||
Poco::Net::HTTPServerResponse & response_,
|
||||
bool compress_,
|
||||
ZlibCompressionMethod compression_method_,
|
||||
size_t size)
|
||||
: BufferWithOwnMemory<WriteBuffer>(size), response(response_),
|
||||
: BufferWithOwnMemory<WriteBuffer>(size), request(request_), response(response_),
|
||||
compress(compress_), compression_method(compression_method_)
|
||||
{
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <mutex>
|
||||
#include <Poco/Net/HTTPServerRequest.h>
|
||||
#include <Poco/Net/HTTPServerResponse.h>
|
||||
#include <Poco/Version.h>
|
||||
#include <IO/WriteBuffer.h>
|
||||
#include <IO/BufferWithOwnMemory.h>
|
||||
@ -41,6 +43,7 @@ namespace DB
|
||||
class WriteBufferFromHTTPServerResponse : public BufferWithOwnMemory<WriteBuffer>
|
||||
{
|
||||
private:
|
||||
Poco::Net::HTTPServerRequest & request;
|
||||
Poco::Net::HTTPServerResponse & response;
|
||||
|
||||
bool add_cors_header = false;
|
||||
@ -81,6 +84,7 @@ private:
|
||||
|
||||
public:
|
||||
WriteBufferFromHTTPServerResponse(
|
||||
Poco::Net::HTTPServerRequest & request_,
|
||||
Poco::Net::HTTPServerResponse & response_,
|
||||
bool compress_ = false, /// If true - set Content-Encoding header and compress the result.
|
||||
ZlibCompressionMethod compression_method_ = ZlibCompressionMethod::Gzip,
|
||||
|
@ -297,7 +297,7 @@ void HTTPHandler::processQuery(
|
||||
size_t buffer_size_memory = (buffer_size_total > buffer_size_http) ? buffer_size_total : 0;
|
||||
|
||||
used_output.out = std::make_shared<WriteBufferFromHTTPServerResponse>(
|
||||
response, client_supports_http_compression, http_response_compression_method, buffer_size_http);
|
||||
request, response, client_supports_http_compression, http_response_compression_method, buffer_size_http);
|
||||
if (internal_compression)
|
||||
used_output.out_maybe_compressed = std::make_shared<CompressedWriteBuffer>(*used_output.out);
|
||||
else
|
||||
|
@ -36,7 +36,7 @@ void InterserverIOHTTPHandler::processQuery(Poco::Net::HTTPServerRequest & reque
|
||||
|
||||
ReadBufferFromIStream body(request.stream());
|
||||
|
||||
WriteBufferFromHTTPServerResponse out(response);
|
||||
WriteBufferFromHTTPServerResponse out(request, response);
|
||||
|
||||
auto endpoint = server.context().getInterserverIOHandler().getEndpoint(endpoint_name);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
clickhouse-client -q "DROP TABLE IF EXISTS test.ws";
|
||||
clickhouse-client -q "CREATE TABLE test.ws (i UInt8) ENGINE = Memory";
|
||||
|
4
dbms/tests/queries/0_stateless/00498_http_head.sh
Executable file
4
dbms/tests/queries/0_stateless/00498_http_head.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
curl -s -X "HEAD" 'http://localhost:8123/?query=SELECT%201'
|
||||
curl -s -X "HEAD" 'http://localhost:8123/?query=select+*+from+system.numbers+limit+1000000'
|
Loading…
Reference in New Issue
Block a user