MCPcopy Create free account
hub / github.com/ByConity/ByConity / handleRequest

Method handleRequest

src/Server/StaticRequestHandler.cpp:102–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void 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
134void StaticRequestHandler::writeResponse(WriteBuffer & out)
135{

Callers

nothing calls this directly

Calls 11

responseWriteBufferFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
trySendExceptionToClientFunction · 0.85
ExceptionClass · 0.50
getUIntMethod · 0.45
configMethod · 0.45
getVersionMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected