| 34 | } |
| 35 | |
| 36 | static inline WriteBufferPtr |
| 37 | responseWriteBuffer(HTTPServerRequest & request, HTTPServerResponse & response, unsigned int keep_alive_timeout) |
| 38 | { |
| 39 | /// The client can pass a HTTP header indicating supported compression method (gzip or deflate). |
| 40 | String http_response_compression_methods = request.get("Accept-Encoding", ""); |
| 41 | CompressionMethod http_response_compression_method = CompressionMethod::None; |
| 42 | |
| 43 | if (!http_response_compression_methods.empty()) |
| 44 | { |
| 45 | /// If client supports brotli - it's preferred. |
| 46 | /// Both gzip and deflate are supported. If the client supports both, gzip is preferred. |
| 47 | /// NOTE parsing of the list of methods is slightly incorrect. |
| 48 | |
| 49 | if (std::string::npos != http_response_compression_methods.find("br")) |
| 50 | http_response_compression_method = CompressionMethod::Brotli; |
| 51 | else if (std::string::npos != http_response_compression_methods.find("gzip")) |
| 52 | http_response_compression_method = CompressionMethod::Gzip; |
| 53 | else if (std::string::npos != http_response_compression_methods.find("deflate")) |
| 54 | http_response_compression_method = CompressionMethod::Zlib; |
| 55 | } |
| 56 | |
| 57 | bool client_supports_http_compression = http_response_compression_method != CompressionMethod::None; |
| 58 | |
| 59 | return std::make_shared<WriteBufferFromHTTPServerResponse>( |
| 60 | response, |
| 61 | request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD, |
| 62 | keep_alive_timeout, |
| 63 | client_supports_http_compression, |
| 64 | http_response_compression_method); |
| 65 | } |
| 66 | |
| 67 | static inline void trySendExceptionToClient( |
| 68 | const std::string & s, int exception_code, HTTPServerRequest & request, HTTPServerResponse & response, WriteBuffer & out) |
no test coverage detected