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

Function http_request_cb

src/httpserver.cpp:233–304  ·  view source on GitHub ↗

HTTP request callback */

Source from the content-addressed store, hash-verified

231
232/** HTTP request callback */
233static void http_request_cb(struct evhttp_request *req, void *arg)
234{
235 // Disable reading to work around a libevent bug, fixed in 2.2.0.
236 if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001)
237 {
238 evhttp_connection *conn = evhttp_request_get_connection(req);
239 if (conn)
240 {
241 bufferevent *bev = evhttp_connection_get_bufferevent(conn);
242 if (bev)
243 {
244 bufferevent_disable(bev, EV_READ);
245 }
246 }
247 }
248 std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));
249
250 LOG(HTTP, "Received a %s request for %s from %s\n", RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(),
251 hreq->GetPeer().ToString());
252
253 // Early address-based allow check
254 if (!ClientAllowed(hreq->GetPeer()))
255 {
256 hreq->WriteReply(HTTP_FORBIDDEN);
257 return;
258 }
259
260 // Early reject unknown HTTP methods
261 if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN)
262 {
263 hreq->WriteReply(HTTP_BADMETHOD);
264 return;
265 }
266
267 // Find registered handler for prefix
268 std::string strURI = hreq->GetURI();
269 std::string path;
270 std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
271 std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
272 for (; i != iend; ++i)
273 {
274 bool match = false;
275 if (i->exactMatch)
276 match = (strURI == i->prefix);
277 else
278 match = (strURI.substr(0, i->prefix.size()) == i->prefix);
279 if (match)
280 {
281 path = strURI.substr(i->prefix.size());
282 break;
283 }
284 }
285
286 // Dispatch to worker thread
287 if (i != iend)
288 {
289 std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(std::move(hreq), path, i->handler));
290 assert(workQueue);

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
ToStringMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected