Bitcoin Core 31.99.0
P2P Digital Currency
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
httpserver.h File Reference
#include <atomic>
#include <functional>
#include <memory>
#include <optional>
#include <span>
#include <stdexcept>
#include <string>
#include <vector>
#include <netaddress.h>
#include <rpc/protocol.h>
#include <util/byte_units.h>
#include <util/expected.h>
#include <util/sock.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/threadinterrupt.h>
#include <util/time.h>
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

struct  bitcoin_http::ContentTooLargeError
 Thrown when a request body exceeds MAX_BODY_SIZE (or will exceed, in chunked transfer) so the server can reply with more specific code 413 (content too large) vs general 400 (bad request) More...
 
class  HTTPHeaders
 
struct  HTTPVersion
 
struct  HTTPResponse
 
class  HTTPRequest
 
class  HTTPServer
 
struct  HTTPServer::IOReadiness
 Info about which socket has which event ready and a reverse map back to the HTTPRemoteClient that owns the socket. More...
 
class  HTTPRemoteClient
 

Namespaces

namespace  util
 
namespace  bitcoin_http
 

Typedefs

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

Enumerations

enum class  HTTPRequestMethod {
  UNKNOWN , GET , POST , HEAD ,
  PUT
}
 

Functions

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...
 
std::optional< std::string > GetQueryParameterFromUri (std::string_view uri, std::string_view key)
 
bool InitHTTPServer ()
 Initialize HTTP server. More...
 
void StartHTTPServer ()
 Start HTTP server. More...
 
void InterruptHTTPServer ()
 Interrupt HTTP server threads. More...
 
void StopHTTPServer ()
 Stop HTTP server. More...
 

Variables

constexpr int DEFAULT_HTTP_THREADS =16
 The default value for -rpcthreads. More...
 
constexpr int DEFAULT_HTTP_WORKQUEUE =64
 The default value for -rpcworkqueue. More...
 
constexpr int DEFAULT_HTTP_SERVER_TIMEOUT =30
 
constexpr int DEFAULT_MAX_HTTP_CONNECTIONS = 16
 Maximum number of connected HTTP clients. More...
 
constexpr size_t bitcoin_http::MIN_REQUEST_LINE_LENGTH = std::string_view("GET / HTTP/1.0").size()
 Shortest valid request line, used by libevent in evhttp_parse_request_line() More...
 
constexpr size_t bitcoin_http::MAX_HEADERS_SIZE {8192}
 Maximum size of each headers line in an HTTP request, also the maximum size of all headers total. More...
 
constexpr uint64_t bitcoin_http::MAX_BODY_SIZE {32_MiB}
 Maximum size of an HTTP request body. More...
 

Typedef Documentation

◆ HTTPRequestHandler

using HTTPRequestHandler = std::function<void(HTTPRequest* req, const std::string&)>

Handler for requests to a certain HTTP path.

Definition at line 60 of file httpserver.h.

Enumeration Type Documentation

◆ HTTPRequestMethod

enum class HTTPRequestMethod
strong
Enumerator
UNKNOWN 
GET 
POST 
HEAD 
PUT 

Definition at line 49 of file httpserver.h.

Function Documentation

◆ GetQueryParameterFromUri()

std::optional< std::string > GetQueryParameterFromUri ( std::string_view  uri,
std::string_view  key 
)

Definition at line 673 of file httpserver.cpp.

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

◆ InitHTTPServer()

bool InitHTTPServer ( )

Initialize HTTP server.

Call this before RegisterHTTPHandler or EventBase().

Definition at line 1298 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 1352 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 241 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 1344 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 1364 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 248 of file httpserver.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_HTTP_SERVER_TIMEOUT

constexpr int DEFAULT_HTTP_SERVER_TIMEOUT =30
inlineconstexpr

Definition at line 42 of file httpserver.h.

◆ DEFAULT_HTTP_THREADS

constexpr int DEFAULT_HTTP_THREADS =16
inlineconstexpr

The default value for -rpcthreads.

This number of threads will be created at startup.

Definition at line 34 of file httpserver.h.

◆ DEFAULT_HTTP_WORKQUEUE

constexpr int DEFAULT_HTTP_WORKQUEUE =64
inlineconstexpr

The default value for -rpcworkqueue.

This is the maximum depth of the work queue, we don't allocate this number of work queue items upfront.

Definition at line 40 of file httpserver.h.

◆ DEFAULT_MAX_HTTP_CONNECTIONS

constexpr int DEFAULT_MAX_HTTP_CONNECTIONS = 16
inlineconstexpr

Maximum number of connected HTTP clients.

Definition at line 47 of file httpserver.h.