5 #ifndef FABCOIN_HTTPSERVER_H 6 #define FABCOIN_HTTPSERVER_H 12 #include <condition_variable> 14 static const int DEFAULT_HTTP_THREADS=4;
15 static const int DEFAULT_HTTP_WORKQUEUE=16;
16 static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
18 struct evhttp_request;
62 struct evhttp_request*
req;
105 std::pair<bool, std::string>
GetHeader(
const std::string& hdr);
120 void WriteHeader(
const std::string& hdr,
const std::string& value);
130 void WriteReply(
int nStatus,
const std::string& strReply =
"");
135 void Chunk(
const std::string& chunk);
153 virtual void operator()() = 0;
172 void trigger(
struct timeval* tv);
181 std::string
urlDecode(
const std::string &urlEncoded);
183 #endif // FABCOIN_HTTPSERVER_H bool(* handler)(HTTPRequest *req, const std::string &strReq)
#define function(a, b, c, d, k, s)
bool ReplySent()
Is reply sent?
HTTPRequest(struct evhttp_request *req)
bool InitHTTPServer()
Initialize HTTP server.
std::pair< bool, std::string > GetHeader(const std::string &hdr)
Get the request header specified by hdr, or an empty string.
std::string GetURI()
Get requested URI.
void Chunk(const std::string &chunk)
Start chunk transfer.
struct evhttp_request * req
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
void InterruptHTTPServer()
Interrupt HTTP server threads.
RequestMethod GetRequestMethod()
Get request method.
void ChunkEnd()
End chunk transfer.
void WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
struct event_base * EventBase()
Return evhttp event base.
void startDetectClientClose()
A combination of a network address (CNetAddr) and a (TCP) port.
struct evbuffer * databuf
std::function< void(void)> handler
CService GetPeer()
Get CService (address:ip) for the origin of the http request.
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
std::string urlDecode(const std::string &urlEncoded)
bool startedChunkTransfer
std::function< bool(HTTPRequest *req, const std::string &)> HTTPRequestHandler
Handler for requests to a certain HTTP path.
std::string ReadBody()
Read request body.
bool StartHTTPServer()
Start HTTP server.
void StopHTTPServer()
Stop HTTP server.
std::condition_variable closeCv