Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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
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.

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.
void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
 Unregister handler for prefix.
std::optional< std::string > GetQueryParameterFromUri (std::string_view uri, std::string_view key)
bool InitHTTPServer ()
 Initialize HTTP server.
void StartHTTPServer ()
 Start HTTP server.
void InterruptHTTPServer ()
 Interrupt HTTP server threads.
void StopHTTPServer ()
 Stop HTTP server.

Variables

constexpr int DEFAULT_HTTP_THREADS =16
 The default value for -rpcthreads.
constexpr int DEFAULT_HTTP_WORKQUEUE =64
 The default value for -rpcworkqueue.
constexpr int DEFAULT_HTTP_SERVER_TIMEOUT =30
constexpr int DEFAULT_MAX_HTTP_CONNECTIONS = 16
 Maximum number of connected HTTP clients.
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().
constexpr size_t bitcoin_http::MAX_HEADERS_SIZE {8192}
constexpr uint64_t bitcoin_http::MAX_BODY_SIZE {32_MiB}

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 1351 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 1405 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 call graph for this function:
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 1397 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 1417 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 call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_HTTP_SERVER_TIMEOUT

int DEFAULT_HTTP_SERVER_TIMEOUT =30
inlineconstexpr

Definition at line 42 of file httpserver.h.

◆ DEFAULT_HTTP_THREADS

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

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

int DEFAULT_MAX_HTTP_CONNECTIONS = 16
inlineconstexpr

Maximum number of connected HTTP clients.

Definition at line 47 of file httpserver.h.