Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Namespaces | Typedefs | Functions | Variables
httpserver.h File Reference
#include <functional>
#include <optional>
#include <span>
#include <string>
Include dependency graph for httpserver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  HTTPRequest
 In-flight HTTP request. More...
 
class  HTTPClosure
 Event handler closure. More...
 
class  HTTPEvent
 Event class. More...
 

Namespaces

namespace  util
 

Typedefs

typedef std::function< bool(HTTPRequest *req, const std::string &)> HTTPRequestHandler
 Handler for requests to a certain HTTP path. More...
 

Functions

bool InitHTTPServer (const util::SignalInterrupt &interrupt)
 Initialize HTTP server. More...
 
void StartHTTPServer ()
 Start HTTP server. More...
 
void InterruptHTTPServer ()
 Interrupt HTTP server threads. More...
 
void StopHTTPServer ()
 Stop HTTP server. More...
 
void UpdateHTTPServerLogging (bool enable)
 Change logging level for libevent. More...
 
void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
 Register handler for prefix. More...
 
void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
 Unregister handler for prefix. More...
 
struct event_base * EventBase ()
 Return evhttp event base. More...
 
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 found. More...
 

Variables

static const int DEFAULT_HTTP_THREADS =4
 
static const int DEFAULT_HTTP_WORKQUEUE =16
 
static const int DEFAULT_HTTP_SERVER_TIMEOUT =30
 

Typedef Documentation

◆ HTTPRequestHandler

typedef std::function<bool(HTTPRequest* req, const std::string &)> HTTPRequestHandler

Handler for requests to a certain HTTP path.

Definition at line 44 of file httpserver.h.

Function Documentation

◆ EventBase()

struct event_base * EventBase ( )

Return evhttp event base.

This can be used by submodules to queue timers or custom events.

Definition at line 559 of file httpserver.cpp.

Here is the caller graph for this function:

◆ GetQueryParameterFromUri()

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 found.

If the query string contains duplicate keys, the first value is returned. Many web frameworks would instead parse this as an array of values, but this is not (yet) implemented as it is currently not needed in any of the endpoints.

Helper function for HTTPRequest::GetQueryParameter.

Parameters
[in]uriis the entire request uri
[in]keyrepresents the query parameter of which the value is returned

Definition at line 726 of file httpserver.cpp.

Here is the caller graph for this function:

◆ InitHTTPServer()

bool InitHTTPServer ( const util::SignalInterrupt interrupt)

Initialize HTTP server.

Call this before RegisterHTTPHandler or EventBase().

Definition at line 437 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InterruptHTTPServer()

void InterruptHTTPServer ( )

Interrupt HTTP server threads.

Definition at line 506 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterHTTPHandler()

void RegisterHTTPHandler ( const std::string &  prefix,
bool  exactMatch,
const HTTPRequestHandler handler 
)

Register handler for prefix.

If multiple handlers match a prefix, the first-registered one will be invoked.

Definition at line 753 of file httpserver.cpp.

Here is the caller graph for this function:

◆ StartHTTPServer()

void StartHTTPServer ( )

Start HTTP server.

This is separate from InitHTTPServer to give users race-condition-free time to register their handlers between InitHTTPServer and StartHTTPServer.

Definition at line 495 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StopHTTPServer()

void StopHTTPServer ( )

Stop HTTP server.

Definition at line 518 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnregisterHTTPHandler()

void UnregisterHTTPHandler ( const std::string &  prefix,
bool  exactMatch 
)

Unregister handler for prefix.

Definition at line 760 of file httpserver.cpp.

Here is the caller graph for this function:

◆ UpdateHTTPServerLogging()

void UpdateHTTPServerLogging ( bool  enable)

Change logging level for libevent.

Definition at line 484 of file httpserver.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_HTTP_SERVER_TIMEOUT

const int DEFAULT_HTTP_SERVER_TIMEOUT =30
static

Definition at line 19 of file httpserver.h.

◆ DEFAULT_HTTP_THREADS

const int DEFAULT_HTTP_THREADS =4
static

Definition at line 17 of file httpserver.h.

◆ DEFAULT_HTTP_WORKQUEUE

const int DEFAULT_HTTP_WORKQUEUE =16
static

Definition at line 18 of file httpserver.h.