MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / http_request_cb

Function http_request_cb

src/httpserver.cpp:279–372  ·  view source on GitHub ↗

HTTP request callback */

Source from the content-addressed store, hash-verified

277
278/** HTTP request callback */
279static void http_request_cb(struct evhttp_request *req, void *arg) {
280 Config &config = *reinterpret_cast<Config *>(arg);
281
282 evhttp_connection *conn{evhttp_request_get_connection(req)};
283 // Track active requests
284 {
285 g_requests.AddRequest(req);
286 evhttp_request_set_on_complete_cb(
287 req,
288 [](struct evhttp_request *req, void *) {
289 g_requests.RemoveRequest(req);
290 },
291 nullptr);
292 evhttp_connection_set_closecb(
293 conn,
294 [](evhttp_connection *conn, void *arg) {
295 g_requests.RemoveConnection(conn);
296 },
297 nullptr);
298 }
299
300 // Disable reading to work around a libevent bug, fixed in 2.2.0.
301 if (event_get_version_number() >= 0x02010600 &&
302 event_get_version_number() < 0x02020001) {
303 if (conn) {
304 bufferevent *bev = evhttp_connection_get_bufferevent(conn);
305 if (bev) {
306 bufferevent_disable(bev, EV_READ);
307 }
308 }
309 }
310 auto hreq = std::make_unique<HTTPRequest>(req);
311
312 // Early address-based allow check
313 if (!ClientAllowed(hreq->GetPeer())) {
314 LogPrint(BCLog::HTTP,
315 "HTTP request from %s rejected: Client network is not allowed "
316 "RPC access\n",
317 hreq->GetPeer().ToStringAddrPort());
318 hreq->WriteReply(HTTP_FORBIDDEN);
319 return;
320 }
321
322 // Early reject unknown HTTP methods
323 if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) {
324 LogPrint(BCLog::HTTP,
325 "HTTP request from %s rejected: Unknown HTTP request method\n",
326 hreq->GetPeer().ToStringAddrPort());
327 hreq->WriteReply(HTTP_BAD_METHOD);
328 return;
329 }
330
331 LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
332 RequestMethodString(hreq->GetRequestMethod()),
333 SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100),
334 hreq->GetPeer().ToStringAddrPort());
335
336 // Find registered handler for prefix

Callers

nothing calls this directly

Calls 13

ClientAllowedFunction · 0.85
RequestMethodStringFunction · 0.85
SanitizeStringFunction · 0.85
GetPeerMethod · 0.80
ToStringAddrPortMethod · 0.80
WriteReplyMethod · 0.80
GetRequestMethodMethod · 0.80
GetURIMethod · 0.80
getMethod · 0.65
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected