Changeset View
Changeset View
Standalone View
Standalone View
src/httpserver.cpp
Show First 20 Lines • Show All 559 Lines • ▼ Show 20 Lines | 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, "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> HTTPRequest::GetHeader(const std::string &hdr) { | std::pair<bool, std::string> | ||||
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); | ||||
const char *val = evhttp_find_header(headers, hdr.c_str()); | const char *val = evhttp_find_header(headers, hdr.c_str()); | ||||
if (val) { | if (val) { | ||||
return std::make_pair(true, val); | return std::make_pair(true, val); | ||||
} else { | } else { | ||||
return std::make_pair(false, ""); | return std::make_pair(false, ""); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | HTTPEvent *ev = new HTTPEvent(eventBase, true, [req_copy, nStatus] { | ||||
} | } | ||||
}); | }); | ||||
ev->trigger(nullptr); | ev->trigger(nullptr); | ||||
replySent = true; | replySent = true; | ||||
// transferred back to main thread. | // transferred back to main thread. | ||||
req = nullptr; | req = nullptr; | ||||
} | } | ||||
CService HTTPRequest::GetPeer() { | CService HTTPRequest::GetPeer() const { | ||||
evhttp_connection *con = evhttp_request_get_connection(req); | evhttp_connection *con = evhttp_request_get_connection(req); | ||||
CService peer; | CService peer; | ||||
if (con) { | if (con) { | ||||
// evhttp retains ownership over returned address string | // evhttp retains ownership over returned address string | ||||
const char *address = ""; | const char *address = ""; | ||||
uint16_t port = 0; | uint16_t port = 0; | ||||
evhttp_connection_get_peer(con, (char **)&address, &port); | evhttp_connection_get_peer(con, (char **)&address, &port); | ||||
peer = LookupNumeric(address, port); | peer = LookupNumeric(address, port); | ||||
} | } | ||||
return peer; | return peer; | ||||
} | } | ||||
std::string HTTPRequest::GetURI() { | std::string HTTPRequest::GetURI() const { | ||||
return evhttp_request_get_uri(req); | return evhttp_request_get_uri(req); | ||||
} | } | ||||
HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() { | HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() const { | ||||
switch (evhttp_request_get_command(req)) { | switch (evhttp_request_get_command(req)) { | ||||
case EVHTTP_REQ_GET: | case EVHTTP_REQ_GET: | ||||
return GET; | return GET; | ||||
case EVHTTP_REQ_POST: | case EVHTTP_REQ_POST: | ||||
return POST; | return POST; | ||||
case EVHTTP_REQ_HEAD: | case EVHTTP_REQ_HEAD: | ||||
return HEAD; | return HEAD; | ||||
case EVHTTP_REQ_PUT: | case EVHTTP_REQ_PUT: | ||||
Show All 30 Lines |