![]() |
Dash Core
0.12.2.1
P2P Digital Currency
|
#include <httpserver.h>
Public Types | |
enum | RequestMethod { UNKNOWN, GET, POST, HEAD, PUT } |
Public Member Functions | |
HTTPRequest (struct evhttp_request *req) | |
~HTTPRequest () | |
std::string | GetURI () |
CService | GetPeer () |
RequestMethod | GetRequestMethod () |
std::pair< bool, std::string > | GetHeader (const std::string &hdr) |
std::string | ReadBody () |
void | WriteHeader (const std::string &hdr, const std::string &value) |
void | WriteReply (int nStatus, const std::string &strReply="") |
Private Attributes | |
struct evhttp_request * | req |
bool | replySent |
In-flight HTTP request. Thin C++ wrapper around evhttp_request.
Definition at line 55 of file httpserver.h.
Enumerator | |
---|---|
UNKNOWN | |
GET | |
POST | |
HEAD | |
PUT |
Definition at line 65 of file httpserver.h.
HTTPRequest::HTTPRequest | ( | struct evhttp_request * | req | ) |
Definition at line 554 of file httpserver.cpp.
HTTPRequest::~HTTPRequest | ( | ) |
Definition at line 558 of file httpserver.cpp.
std::pair< bool, std::string > HTTPRequest::GetHeader | ( | const std::string & | hdr | ) |
Get the request header specified by hdr, or an empty string. Return an pair (isPresent,string).
Definition at line 568 of file httpserver.cpp.
Referenced by HTTPReq_JSONRPC().
CService HTTPRequest::GetPeer | ( | ) |
Get CService (address:ip) for the origin of the http request.
Definition at line 625 of file httpserver.cpp.
Referenced by HTTPReq_JSONRPC().
HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod | ( | ) |
std::string HTTPRequest::GetURI | ( | ) |
Get requested URI.
Definition at line 639 of file httpserver.cpp.
std::string HTTPRequest::ReadBody | ( | ) |
Read request body.
Trivial implementation: if this is ever a performance bottleneck, internal copying can be avoided in multi-segment buffers by using evbuffer_peek and an awkward loop. Though in that case, it'd be even better to not copy into an intermediate string but use a stream abstraction to consume the evbuffer on the fly in the parsing algorithm.
Definition at line 579 of file httpserver.cpp.
Referenced by HTTPReq_JSONRPC(), and rest_getutxos().
void HTTPRequest::WriteHeader | ( | const std::string & | hdr, |
const std::string & | value | ||
) |
Write output header.
Definition at line 599 of file httpserver.cpp.
Referenced by HTTPReq_JSONRPC(), JSONErrorReply(), rest_block(), rest_chaininfo(), rest_getutxos(), rest_headers(), rest_mempool_contents(), rest_mempool_info(), rest_tx(), and RESTERR().
void HTTPRequest::WriteReply | ( | int | nStatus, |
const std::string & | strReply = "" |
||
) |
Write HTTP reply. nStatus is the HTTP status code to send. strReply is the body of the reply. Keep it empty to send a standard message.
Closure sent to main thread to request a reply to be sent to a HTTP request. Replies must be sent in the main loop in the main http thread, this cannot be done from worker threads.
Definition at line 611 of file httpserver.cpp.
Referenced by HTTPReq_JSONRPC(), JSONErrorReply(), rest_block(), rest_chaininfo(), rest_getutxos(), rest_headers(), rest_mempool_contents(), rest_mempool_info(), rest_tx(), RESTERR(), and ~HTTPRequest().
|
private |
Definition at line 59 of file httpserver.h.
Referenced by WriteReply(), and ~HTTPRequest().
|
private |
Definition at line 58 of file httpserver.h.
Referenced by GetHeader(), GetPeer(), GetRequestMethod(), GetURI(), ReadBody(), WriteHeader(), and WriteReply().