| 100 | } |
| 101 | |
| 102 | void StaticRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response) |
| 103 | { |
| 104 | auto keep_alive_timeout = server.config().getUInt("keep_alive_timeout", 10); |
| 105 | const auto & out = responseWriteBuffer(request, response, keep_alive_timeout); |
| 106 | |
| 107 | try |
| 108 | { |
| 109 | response.setContentType(content_type); |
| 110 | |
| 111 | if (request.getVersion() == Poco::Net::HTTPServerRequest::HTTP_1_1) |
| 112 | response.setChunkedTransferEncoding(true); |
| 113 | |
| 114 | /// Workaround. Poco does not detect 411 Length Required case. |
| 115 | if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST && !request.getChunkedTransferEncoding() && !request.hasContentLength()) |
| 116 | throw Exception("The Transfer-Encoding is not chunked and there is no Content-Length header for POST request", ErrorCodes::HTTP_LENGTH_REQUIRED); |
| 117 | |
| 118 | setResponseDefaultHeaders(response, keep_alive_timeout); |
| 119 | response.setStatusAndReason(Poco::Net::HTTPResponse::HTTPStatus(status)); |
| 120 | writeResponse(*out); |
| 121 | } |
| 122 | catch (...) |
| 123 | { |
| 124 | tryLogCurrentException("StaticRequestHandler"); |
| 125 | |
| 126 | int exception_code = getCurrentExceptionCode(); |
| 127 | std::string exception_message = getCurrentExceptionMessage(false, true); |
| 128 | trySendExceptionToClient(exception_message, exception_code, request, response, *out); |
| 129 | } |
| 130 | |
| 131 | out->finalize(); |
| 132 | } |
| 133 | |
| 134 | void StaticRequestHandler::writeResponse(WriteBuffer & out) |
| 135 | { |
nothing calls this directly
no test coverage detected