MCPcopy Create free account
hub / github.com/dogecoin/dogecoin / http_request_cb

Function http_request_cb

src/httpserver.cpp:251–300  ·  view source on GitHub ↗

HTTP request callback */

Source from the content-addressed store, hash-verified

249
250/** HTTP request callback */
251static void http_request_cb(struct evhttp_request* req, void* arg)
252{
253 std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));
254
255 LogPrint("http", "Received a %s request for %s from %s\n",
256 RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString());
257
258 // Early address-based allow check
259 if (!ClientAllowed(hreq->GetPeer())) {
260 hreq->WriteReply(HTTP_FORBIDDEN);
261 return;
262 }
263
264 // Early reject unknown HTTP methods
265 if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) {
266 hreq->WriteReply(HTTP_BADMETHOD);
267 return;
268 }
269
270 // Find registered handler for prefix
271 std::string strURI = hreq->GetURI();
272 std::string path;
273 std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
274 std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
275 for (; i != iend; ++i) {
276 bool match = false;
277 if (i->exactMatch)
278 match = (strURI == i->prefix);
279 else
280 match = (strURI.substr(0, i->prefix.size()) == i->prefix);
281 if (match) {
282 path = strURI.substr(i->prefix.size());
283 break;
284 }
285 }
286
287 // Dispatch to worker thread
288 if (i != iend) {
289 std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(std::move(hreq), path, i->handler));
290 assert(workQueue);
291 if (workQueue->Enqueue(item.get()))
292 item.release(); /* if true, queue took ownership */
293 else {
294 LogPrintf("WARNING: request rejected because http work queue depth exceeded, it can be increased with the -rpcworkqueue= setting\n");
295 item->req->WriteReply(HTTP_INTERNAL, "Work queue depth exceeded");
296 }
297 } else {
298 hreq->WriteReply(HTTP_NOTFOUND);
299 }
300}
301
302/** Callback to reject HTTP requests after shutdown. */
303static void http_reject_request_cb(struct evhttp_request* req, void*)

Callers

nothing calls this directly

Calls 13

RequestMethodStringFunction · 0.85
ClientAllowedFunction · 0.85
GetRequestMethodMethod · 0.80
GetURIMethod · 0.80
GetPeerMethod · 0.80
WriteReplyMethod · 0.80
EnqueueMethod · 0.80
releaseMethod · 0.80
ToStringMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected