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

Method handleRequest

src/Server/APIRequestHandler.cpp:146–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146void APIRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response)
147{
148 setThreadName("APIHandler");
149 ThreadStatus thread_status;
150
151 bool with_stacktrace = false;
152
153 try
154 {
155 const auto & uri = request.getURI();
156 LOG_TRACE(log, "Request URI: {}", request.getURI());
157
158 response.setContentType("application/json; charset=utf-8");
159 response.set("X-ClickHouse-Server-Display-Name", server_display_name);
160
161 /// For keep-alive to work.
162 if (request.getVersion() == Poco::Net::HTTPServerRequest::HTTP_1_1)
163 response.setChunkedTransferEncoding(true);
164
165 HTMLForm params(getContext()->getSettingsRef(), request);
166 with_stacktrace = params.getParsed<bool>("stacktrace", false);
167
168 if (startsWith(uri, "/api/resource_report"))
169 {
170 onResourceReportAction(request, params, response);
171 }
172 else
173 {
174 throw Exception("No such API", ErrorCodes::BAD_ARGUMENTS);
175 }
176
177 LOG_DEBUG(log, "Done processing API request");
178 }
179 catch (...)
180 {
181 tryLogCurrentException(log);
182
183 /** If exception is received from remote server, then stack trace is embedded in message.
184 * If exception is thrown on local server, then stack trace is in separate field.
185 */
186 std::string exception_message = getCurrentExceptionMessage(with_stacktrace, true);
187 int exception_code = getCurrentExceptionCode();
188
189 try
190 {
191 trySendExceptionToClient(exception_message, exception_code, request, response);
192 }
193 catch (...)
194 {
195 tryLogCurrentException(log, "Cannot send exception to client");
196 }
197 }
198}
199
200void APIRequestHandler::sendResult(const Result & res, HTTPServerResponse & response)
201{

Callers

nothing calls this directly

Calls 9

setThreadNameFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
trySendExceptionToClientFunction · 0.85
startsWithFunction · 0.50
ExceptionClass · 0.50
setMethod · 0.45
getVersionMethod · 0.45

Tested by

no test coverage detected