6 #ifndef RAVEN_HTTPSERVER_H 7 #define RAVEN_HTTPSERVER_H 13 static const int DEFAULT_HTTP_THREADS=4;
14 static const int DEFAULT_HTTP_WORKQUEUE=16;
15 static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
17 struct evhttp_request;
61 struct evhttp_request*
req;
92 std::pair<bool, std::string>
GetHeader(
const std::string& hdr);
107 void WriteHeader(
const std::string& hdr,
const std::string& value);
117 void WriteReply(
int nStatus,
const std::string& strReply =
"");
125 virtual void operator()() = 0;
138 HTTPEvent(
struct event_base* base,
bool deleteWhenTriggered,
const std::function<
void(
void)>&
handler);
144 void trigger(
struct timeval* tv);
152 std::string
urlDecode(
const std::string &urlEncoded);
154 #endif // RAVEN_HTTPSERVER_H bool(* handler)(HTTPRequest *req, const std::string &strReq)
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.
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 WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
struct event_base * EventBase()
Return evhttp event base.
A combination of a network address (CNetAddr) and a (TCP) port.
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)
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.