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

Function http_request_cb

src/httpserver.cpp:218–265  ·  view source on GitHub ↗

HTTP request callback */

Source from the content-addressed store, hash-verified

216
217/** HTTP request callback */
218static void http_request_cb(struct evhttp_request* req, void* arg)
219{
220 std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));
221
222 LogPrint("http", "Received a %s request for %s from %s\n",
223 RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString());
224
225 // Early address-based allow check
226 if (!ClientAllowed(hreq->GetPeer())) {
227 hreq->WriteReply(HTTP_FORBIDDEN);
228 return;
229 }
230
231 // Early reject unknown HTTP methods
232 if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) {
233 hreq->WriteReply(HTTP_BADMETHOD);
234 return;
235 }
236
237 // Find registered handler for prefix
238 std::string strURI = hreq->GetURI();
239 std::string path;
240 std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
241 std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
242 for (; i != iend; ++i) {
243 bool match = false;
244 if (i->exactMatch)
245 match = (strURI == i->prefix);
246 else
247 match = (strURI.substr(0, i->prefix.size()) == i->prefix);
248 if (match) {
249 path = strURI.substr(i->prefix.size());
250 break;
251 }
252 }
253
254 // Dispatch to worker thread
255 if (i != iend) {
256 std::auto_ptr<HTTPWorkItem> item(new HTTPWorkItem(hreq.release(), path, i->handler));
257 assert(workQueue);
258 if (workQueue->Enqueue(item.get()))
259 item.release(); /* if true, queue took ownership */
260 else
261 item->req->WriteReply(HTTP_INTERNAL, "Work queue depth exceeded");
262 } else {
263 hreq->WriteReply(HTTP_NOTFOUND);
264 }
265}
266
267/** Event dispatcher thread */
268static void ThreadHTTP(struct event_base* base, struct evhttp* http)

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
releaseMethod · 0.80
EnqueueMethod · 0.80
ToStringMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected