diff --git a/dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp b/dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp index 36739bf254f..1578deccf90 100644 --- a/dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp +++ b/dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp @@ -83,6 +83,9 @@ void WriteBufferFromHTTPServerResponse::nextImpl() #else response.set("Content-Encoding", "gzip"); #endif + out_raw.emplace(*response_body_ostr); + deflating_buf.emplace(*out_raw, compression_method, compression_level, working_buffer.size(), working_buffer.begin()); + out = &*deflating_buf; } else if (compression_method == CompressionMethod::Zlib) { @@ -91,7 +94,22 @@ void WriteBufferFromHTTPServerResponse::nextImpl() #else response.set("Content-Encoding", "deflate"); #endif + out_raw.emplace(*response_body_ostr); + deflating_buf.emplace(*out_raw, compression_method, compression_level, working_buffer.size(), working_buffer.begin()); + out = &*deflating_buf; } + else if (compression_method == CompressionMethod::Brotli) + { +#if POCO_CLICKHOUSE_PATCH + *response_header_ostr << "Content-Encoding: br\r\n"; +#else + response.set("Content-Encoding", "br"); +#endif + out_raw.emplace(*response_body_ostr); + brotli_buf.emplace(*out_raw, compression_level, working_buffer.size(), working_buffer.begin()); + out = &*deflating_buf; + } + else throw Exception("Logical error: unknown compression method passed to WriteBufferFromHTTPServerResponse", ErrorCodes::LOGICAL_ERROR); @@ -101,9 +119,6 @@ void WriteBufferFromHTTPServerResponse::nextImpl() response_body_ostr = &(response.send()); #endif - out_raw.emplace(*response_body_ostr); - deflating_buf.emplace(*out_raw, compression_method, compression_level, working_buffer.size(), working_buffer.begin()); - out = &*deflating_buf; } else { diff --git a/dbms/src/IO/WriteBufferFromHTTPServerResponse.h b/dbms/src/IO/WriteBufferFromHTTPServerResponse.h index f59b318c6c0..f82e5828694 100644 --- a/dbms/src/IO/WriteBufferFromHTTPServerResponse.h +++ b/dbms/src/IO/WriteBufferFromHTTPServerResponse.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,7 @@ private: std::optional out_raw; std::optional deflating_buf; + std::optional brotli_buf; WriteBuffer * out = nullptr; /// Uncompressed HTTP body is written to this buffer. Points to out_raw or possibly to deflating_buf.