Changeset View
Changeset View
Standalone View
Standalone View
src/httpserver.cpp
Show First 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | if (!ClientAllowed(hreq->GetPeer())) { | ||||
return; | return; | ||||
} | } | ||||
// Early reject unknown HTTP methods | // Early reject unknown HTTP methods | ||||
if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) { | if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) { | ||||
LogPrint(BCLog::HTTP, | LogPrint(BCLog::HTTP, | ||||
"HTTP request from %s rejected: Unknown HTTP request method\n", | "HTTP request from %s rejected: Unknown HTTP request method\n", | ||||
hreq->GetPeer().ToString()); | hreq->GetPeer().ToString()); | ||||
hreq->WriteReply(HTTP_BADMETHOD); | hreq->WriteReply(HTTP_BAD_METHOD); | ||||
return; | return; | ||||
} | } | ||||
LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n", | LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n", | ||||
RequestMethodString(hreq->GetRequestMethod()), | RequestMethodString(hreq->GetRequestMethod()), | ||||
SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), | SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), | ||||
hreq->GetPeer().ToString()); | hreq->GetPeer().ToString()); | ||||
Show All 22 Lines | if (i != iend) { | ||||
assert(workQueue); | assert(workQueue); | ||||
if (workQueue->Enqueue(item.get())) { | if (workQueue->Enqueue(item.get())) { | ||||
/* if true, queue took ownership */ | /* if true, queue took ownership */ | ||||
item.release(); | item.release(); | ||||
} else { | } else { | ||||
LogPrintf("WARNING: request rejected because http work queue depth " | LogPrintf("WARNING: request rejected because http work queue depth " | ||||
"exceeded, it can be increased with the -rpcworkqueue= " | "exceeded, it can be increased with the -rpcworkqueue= " | ||||
"setting\n"); | "setting\n"); | ||||
item->req->WriteReply(HTTP_INTERNAL, "Work queue depth exceeded"); | item->req->WriteReply(HTTP_INTERNAL_SERVER_ERROR, | ||||
"Work queue depth exceeded"); | |||||
} | } | ||||
} else { | } else { | ||||
hreq->WriteReply(HTTP_NOTFOUND); | hreq->WriteReply(HTTP_NOT_FOUND); | ||||
} | } | ||||
} | } | ||||
/** Callback to reject HTTP requests after shutdown. */ | /** Callback to reject HTTP requests after shutdown. */ | ||||
static void http_reject_request_cb(struct evhttp_request *req, void *) { | static void http_reject_request_cb(struct evhttp_request *req, void *) { | ||||
LogPrint(BCLog::HTTP, "Rejecting request while shutting down\n"); | LogPrint(BCLog::HTTP, "Rejecting request while shutting down\n"); | ||||
evhttp_send_error(req, HTTP_SERVUNAVAIL, nullptr); | evhttp_send_error(req, HTTP_SERVUNAVAIL, nullptr); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | void HTTPEvent::trigger(struct timeval *tv) { | ||||
} | } | ||||
} | } | ||||
HTTPRequest::HTTPRequest(struct evhttp_request *_req) | HTTPRequest::HTTPRequest(struct evhttp_request *_req) | ||||
: req(_req), replySent(false) {} | : req(_req), replySent(false) {} | ||||
HTTPRequest::~HTTPRequest() { | HTTPRequest::~HTTPRequest() { | ||||
if (!replySent) { | if (!replySent) { | ||||
// Keep track of whether reply was sent to avoid request leaks | // Keep track of whether reply was sent to avoid request leaks | ||||
LogPrintf("%s: Unhandled request\n", __func__); | LogPrintf("%s: Unhandled request\n", __func__); | ||||
WriteReply(HTTP_INTERNAL, "Unhandled request"); | WriteReply(HTTP_INTERNAL_SERVER_ERROR, "Unhandled request"); | ||||
} | } | ||||
// evhttpd cleans up the request, as long as a reply was sent. | // evhttpd cleans up the request, as long as a reply was sent. | ||||
} | } | ||||
std::pair<bool, std::string> | std::pair<bool, std::string> | ||||
HTTPRequest::GetHeader(const std::string &hdr) const { | HTTPRequest::GetHeader(const std::string &hdr) const { | ||||
const struct evkeyvalq *headers = evhttp_request_get_input_headers(req); | const struct evkeyvalq *headers = evhttp_request_get_input_headers(req); | ||||
assert(headers); | assert(headers); | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |