5#ifndef BITCOIN_HTTPSERVER_H
6#define BITCOIN_HTTPSERVER_H
64 struct evhttp_request*
req;
82 std::string
GetURI()
const;
107 std::pair<bool, std::string>
GetHeader(
const std::string& hdr)
const;
122 void WriteHeader(
const std::string& hdr,
const std::string& value);
134 WriteReply(nStatus, std::as_bytes(std::span{reply}));
136 void WriteReply(
int nStatus, std::span<const std::byte> reply);
177 void trigger(
struct timeval* tv);
A combination of a network address (CNetAddr) and a (TCP) port.
virtual ~HTTPClosure()=default
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::optional< std::string > GetQueryParameter(const std::string &key) const
Get the query parameter value from request uri for a specified key, or std::nullopt if the key is not...
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, std::string_view reply="")
Write HTTP reply.
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
HTTPRequest(struct evhttp_request *req, const util::SignalInterrupt &interrupt, bool replySent=false)
struct evhttp_request * req
RequestMethod GetRequestMethod() const
Get request method.
const util::SignalInterrupt & m_interrupt
std::string ReadBody()
Read request body.
CService GetPeer() const
Get CService (address:ip) for the origin of the http request.
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
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.
std::optional< std::string > GetQueryParameterFromUri(const char *uri, const std::string &key)
Get the query parameter value from request uri for a specified key, or std::nullopt if the key is not...
static const int DEFAULT_HTTP_WORKQUEUE
void StartHTTPServer()
Start HTTP server.
void UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
struct event_base * EventBase()
Return evhttp event base.
static const int DEFAULT_HTTP_THREADS
bool InitHTTPServer(const util::SignalInterrupt &interrupt)
Initialize HTTP server.
std::function< bool(HTTPRequest *req, const std::string &)> HTTPRequestHandler
Handler for requests to a certain HTTP path.
void StopHTTPServer()
Stop HTTP server.
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)