Send X-ClickHouse-Progress header in the end of a query execution

This commit is contained in:
Guillaume Tassery 2019-04-19 19:14:10 +07:00
parent cdc65eca23
commit 7a75003d26
2 changed files with 17 additions and 7 deletions

View File

@ -36,11 +36,24 @@ void WriteBufferFromHTTPServerResponse::startSendHeaders()
} }
} }
void WriteBufferFromHTTPServerResponse::writeHeaderProgress()
{
if (headers_finished_sending)
return;
WriteBufferFromOwnString progress_string_writer;
accumulated_progress.writeJSON(progress_string_writer);
#if defined(POCO_CLICKHOUSE_PATCH)
*response_header_ostr << "X-ClickHouse-Progress: " << progress_string_writer.str() << "\r\n" << std::flush;
#endif
}
void WriteBufferFromHTTPServerResponse::finishSendHeaders() void WriteBufferFromHTTPServerResponse::finishSendHeaders()
{ {
if (!headers_finished_sending) if (!headers_finished_sending)
{ {
writeHeaderProgress();
headers_finished_sending = true; headers_finished_sending = true;
if (request.getMethod() != Poco::Net::HTTPRequest::HTTP_HEAD) if (request.getMethod() != Poco::Net::HTTPRequest::HTTP_HEAD)
@ -174,13 +187,7 @@ void WriteBufferFromHTTPServerResponse::onProgress(const Progress & progress)
/// Send all common headers before our special progress headers. /// Send all common headers before our special progress headers.
startSendHeaders(); startSendHeaders();
writeHeaderProgress();
WriteBufferFromOwnString progress_string_writer;
accumulated_progress.writeJSON(progress_string_writer);
#if defined(POCO_CLICKHOUSE_PATCH)
*response_header_ostr << "X-ClickHouse-Progress: " << progress_string_writer.str() << "\r\n" << std::flush;
#endif
} }
} }

View File

@ -80,6 +80,9 @@ private:
/// but not finish them with \r\n, allowing to send more headers subsequently. /// but not finish them with \r\n, allowing to send more headers subsequently.
void startSendHeaders(); void startSendHeaders();
// Used for write the header X-ClickHouse-progress
void writeHeaderProgress();
/// This method finish headers with \r\n, allowing to start to send body. /// This method finish headers with \r\n, allowing to start to send body.
void finishSendHeaders(); void finishSendHeaders();