mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Correct fix of building with external poco with disabled sending progress (#461)
* Correct fix of building with external poco with disabled sending progress
Revert "Removed wrong code [#CLICKHOUSE-2]."
This reverts commit 33f9917f53
.
* fix
This commit is contained in:
parent
38c900bf2f
commit
083e9cc3aa
@ -2,7 +2,7 @@
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <mutex>
|
||||
|
||||
#include <Poco/Version.h>
|
||||
#include <DB/IO/WriteBuffer.h>
|
||||
#include <DB/IO/BufferWithOwnMemory.h>
|
||||
#include <DB/IO/WriteBufferFromOStream.h>
|
||||
@ -49,7 +49,10 @@ private:
|
||||
int compression_level = Z_DEFAULT_COMPRESSION;
|
||||
|
||||
std::ostream * response_body_ostr = nullptr;
|
||||
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
std::ostream * response_header_ostr = nullptr;
|
||||
#endif
|
||||
|
||||
std::experimental::optional<WriteBufferFromOStream> out_raw;
|
||||
std::experimental::optional<ZlibDeflatingWriteBuffer> deflating_buf;
|
||||
|
@ -1,15 +1,14 @@
|
||||
#include <Poco/Net/HTTPServerResponse.h>
|
||||
|
||||
#include <DB/Common/Exception.h>
|
||||
|
||||
#include <DB/IO/WriteBufferFromHTTPServerResponse.h>
|
||||
|
||||
#include <Poco/Version.h>
|
||||
#include <Poco/Net/HTTPServerResponse.h>
|
||||
#include <DB/Common/Exception.h>
|
||||
#include <DB/IO/WriteBufferFromString.h>
|
||||
#include <DB/IO/HTTPCommon.h>
|
||||
#include <DB/Common/NetException.h>
|
||||
#include <DB/Common/Stopwatch.h>
|
||||
#include <DB/Core/Progress.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -30,7 +29,9 @@ void WriteBufferFromHTTPServerResponse::startSendHeaders()
|
||||
|
||||
setResponseDefaultHeaders(response);
|
||||
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
std::tie(response_header_ostr, response_body_ostr) = response.beginSend();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,8 +42,12 @@ void WriteBufferFromHTTPServerResponse::finishSendHeaders()
|
||||
{
|
||||
headers_finished_sending = true;
|
||||
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
/// Send end of headers delimiter.
|
||||
*response_header_ostr << "\r\n" << std::flush;
|
||||
#else
|
||||
/// Newline autosent by response.send()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,26 +64,47 @@ void WriteBufferFromHTTPServerResponse::nextImpl()
|
||||
if (compress)
|
||||
{
|
||||
if (compression_method == ZlibCompressionMethod::Gzip)
|
||||
{
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
*response_header_ostr << "Content-Encoding: gzip\r\n";
|
||||
#else
|
||||
response.set("Content-Encoding", "gzip");
|
||||
#endif
|
||||
}
|
||||
else if (compression_method == ZlibCompressionMethod::Zlib)
|
||||
{
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
*response_header_ostr << "Content-Encoding: deflate\r\n";
|
||||
#else
|
||||
response.set("Content-Encoding", "deflate");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
throw Exception("Logical error: unknown compression method passed to WriteBufferFromHTTPServerResponse",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
|
||||
/// Use memory allocated for the outer buffer in the buffer pointed to by out. This avoids extra allocation and copy.
|
||||
|
||||
#if !POCO_CLICKHOUSE_PATCH
|
||||
response_body_ostr = &(response.send());
|
||||
#endif
|
||||
|
||||
out_raw.emplace(*response_body_ostr);
|
||||
deflating_buf.emplace(out_raw.value(), compression_method, compression_level, working_buffer.size(), working_buffer.begin());
|
||||
out = &deflating_buf.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !POCO_CLICKHOUSE_PATCH
|
||||
response_body_ostr = &(response.send());
|
||||
#endif
|
||||
|
||||
out_raw.emplace(*response_body_ostr, working_buffer.size(), working_buffer.begin());
|
||||
out = &out_raw.value();
|
||||
}
|
||||
}
|
||||
|
||||
finishSendHeaders();
|
||||
|
||||
}
|
||||
|
||||
out->position() = position();
|
||||
@ -120,7 +146,9 @@ void WriteBufferFromHTTPServerResponse::onProgress(const Progress & progress)
|
||||
accumulated_progress.writeJSON(progress_string_writer);
|
||||
}
|
||||
|
||||
#if POCO_CLICKHOUSE_PATCH
|
||||
*response_header_ostr << "X-ClickHouse-Progress: " << progress_string << "\r\n" << std::flush;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,3 +5,9 @@ curl -sS 'http://localhost:8123/?max_block_size=1&send_progress_in_http_headers=
|
||||
|
||||
# 'send_progress_in_http_headers' is false by default
|
||||
curl -vsS 'http://localhost:8123/?max_block_size=1&http_headers_progress_interval_ms=0' -d 'SELECT number FROM system.numbers LIMIT 10' 2>&1 | grep -q 'X-ClickHouse-Progress' && echo 'Fail' || true
|
||||
|
||||
# have header?
|
||||
curl -vsS 'http://localhost:8123/?max_block_size=1&send_progress_in_http_headers=1&http_headers_progress_interval_ms=0&enable_http_compression=1' -H 'Accept-Encoding: gzip' -d 'SELECT number FROM system.numbers LIMIT 1' 2>&1 | grep -q "Content-Encoding: gzip" && true || echo 'Fail'
|
||||
|
||||
# nothing in body = no gzip
|
||||
curl -vsS 'http://localhost:8123/?max_block_size=1&send_progress_in_http_headers=1&http_headers_progress_interval_ms=0&enable_http_compression=1' -H 'Accept-Encoding: gzip' -d 'SELECT number FROM system.numbers LIMIT 0' 2>&1 | grep -q 'Content-Encoding: gzip' && echo 'Fail' || true
|
||||
|
Loading…
Reference in New Issue
Block a user