6#ifndef BITCOIN_HTTPSERVER_H
7#define BITCOIN_HTTPSERVER_H
76 struct evhttp_request *
req;
86 std::string
GetURI()
const;
98 std::pair<bool, std::string>
GetHeader(
const std::string &hdr)
const;
113 void WriteHeader(
const std::string &hdr,
const std::string &value);
125 void WriteReply(
int nStatus,
const std::string &strReply =
"");
148 const std::function<
void()> &
handler);
155 void trigger(
struct timeval *tv);
A combination of a network address (CNetAddr) and a (TCP) port.
virtual void operator()()=0
std::function< void()> handler
HTTPEvent(struct event_base *base, bool deleteWhenTriggered, const std::function< void()> &handler)
Create a new event.
void trigger(struct timeval *tv)
Trigger the event.
std::pair< bool, std::string > GetHeader(const std::string &hdr) const
Get the request header specified by hdr, or an empty string.
std::string GetURI() const
Get requested URI.
void WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
struct evhttp_request * req
RequestMethod GetRequestMethod() const
Get request method.
std::string ReadBody()
Read request body.
CService GetPeer() const
Get CService (address:ip) for the origin of the http request.
HTTPRequest(struct evhttp_request *req, bool replySent=false)
void InterruptHTTPServer()
Interrupt HTTP server threads.
static const int DEFAULT_HTTP_SERVER_TIMEOUT
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
static const int DEFAULT_HTTP_WORKQUEUE
void StartHTTPServer()
Start HTTP server.
struct event_base * EventBase()
Return evhttp event base.
bool UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
static const int DEFAULT_HTTP_THREADS
std::function< bool(Config &config, HTTPRequest *req, const std::string &)> HTTPRequestHandler
Handler for requests to a certain HTTP path.
void StopHTTPServer()
Stop HTTP server.
bool InitHTTPServer(Config &config)
Initialize HTTP server.
bool(* handler)(Config &config, const std::any &context, HTTPRequest *req, const std::string &strReq)