Fabcoin Core
0.16.2
P2P Digital Currency
|
In-flight HTTP request. More...
#include <httpserver.h>
Public Types | |
enum | RequestMethod { UNKNOWN, GET, POST, HEAD, PUT } |
Public Member Functions | |
HTTPRequest (struct evhttp_request *req) | |
~HTTPRequest () | |
void | setConnClosed () |
bool | isConnClosed () |
bool | isChunkMode () |
std::string | GetURI () |
Get requested URI. More... | |
CService | GetPeer () |
Get CService (address:ip) for the origin of the http request. More... | |
RequestMethod | GetRequestMethod () |
Get request method. More... | |
std::pair< bool, std::string > | GetHeader (const std::string &hdr) |
Get the request header specified by hdr, or an empty string. More... | |
std::string | ReadBody () |
Read request body. More... | |
void | WriteHeader (const std::string &hdr, const std::string &value) |
Write output header. More... | |
void | WriteReply (int nStatus, const std::string &strReply="") |
Write HTTP reply. More... | |
void | Chunk (const std::string &chunk) |
Start chunk transfer. More... | |
void | ChunkEnd () |
End chunk transfer. More... | |
bool | ReplySent () |
Is reply sent? More... | |
Private Member Functions | |
void | startDetectClientClose () |
void | waitClientClose () |
Private Attributes | |
struct evhttp_request * | req |
bool | replySent |
bool | startedChunkTransfer |
bool | connClosed |
std::mutex | cs |
std::condition_variable | closeCv |
In-flight HTTP request.
Thin C++ wrapper around evhttp_request.
Definition at line 59 of file httpserver.h.
Enumerator | |
---|---|
UNKNOWN | |
GET | |
POST | |
HEAD | |
PUT |
Definition at line 77 of file httpserver.h.
HTTPRequest::HTTPRequest | ( | struct evhttp_request * | req | ) |
Definition at line 553 of file httpserver.cpp.
HTTPRequest::~HTTPRequest | ( | ) |
void HTTPRequest::Chunk | ( | const std::string & | chunk | ) |
Start chunk transfer.
Assume to be 200.
Definition at line 689 of file httpserver.cpp.
void HTTPRequest::ChunkEnd | ( | ) |
End chunk transfer.
Definition at line 671 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 a pair (isPresent,string).
Definition at line 629 of file httpserver.cpp.
CService HTTPRequest::GetPeer | ( | ) |
Get CService (address:ip) for the origin of the http request.
Definition at line 746 of file httpserver.cpp.
HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod | ( | ) |
Get request method.
Definition at line 765 of file httpserver.cpp.
std::string HTTPRequest::GetURI | ( | ) |
Get requested URI.
Definition at line 760 of file httpserver.cpp.
bool HTTPRequest::isChunkMode | ( | ) |
Definition at line 625 of file httpserver.cpp.
bool HTTPRequest::isConnClosed | ( | ) |
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 640 of file httpserver.cpp.
bool HTTPRequest::ReplySent | ( | ) |
Is reply sent?
Definition at line 660 of file httpserver.cpp.
void HTTPRequest::setConnClosed | ( | ) |
Definition at line 614 of file httpserver.cpp.
|
private |
Definition at line 587 of file httpserver.cpp.
|
private |
Definition at line 569 of file httpserver.cpp.
void HTTPRequest::WriteHeader | ( | const std::string & | hdr, |
const std::string & | value | ||
) |
Write output header.
Definition at line 664 of file httpserver.cpp.
void HTTPRequest::WriteReply | ( | int | nStatus, |
const std::string & | strReply = "" |
||
) |
Write HTTP reply.
Closure sent to main thread to request a reply to be sent to a HTTP request.
nStatus is the HTTP status code to send. strReply is the body of the reply. Keep it empty to send a standard message.
Replies must be sent in the main loop in the main http thread, this cannot be done from worker threads.
Definition at line 719 of file httpserver.cpp.
|
private |
Definition at line 68 of file httpserver.h.
|
private |
Definition at line 65 of file httpserver.h.
|
private |
Definition at line 67 of file httpserver.h.
|
private |
Definition at line 63 of file httpserver.h.
|
private |
Definition at line 62 of file httpserver.h.
|
private |
Definition at line 64 of file httpserver.h.