Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
httpserver.cpp File Reference
#include <bitcoin-build-config.h>
#include <httpserver.h>
#include <chainparamsbase.h>
#include <common/args.h>
#include <common/messages.h>
#include <common/url.h>
#include <compat/compat.h>
#include <logging.h>
#include <netbase.h>
#include <node/interface_ui.h>
#include <rpc/protocol.h>
#include <span.h>
#include <sync.h>
#include <util/check.h>
#include <util/signalinterrupt.h>
#include <util/sock.h>
#include <util/strencodings.h>
#include <util/thread.h>
#include <util/threadnames.h>
#include <util/threadpool.h>
#include <util/time.h>
#include <util/translation.h>
#include <condition_variable>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <thread>
#include <unordered_map>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
Include dependency graph for httpserver.cpp:

Go to the source code of this file.

Classes

struct  HTTPPathHandler
class  LineReader

Functions

static std::vector< HTTPPathHandler > pathHandlers GUARDED_BY (g_httppathhandlers_mutex)
std::string_view RequestMethodString (HTTPRequestMethod m)
 HTTP request method as string - use for logging only.
static void WriteNoStoreErrorReply (HTTPRequest &req, HTTPStatusCode status, std::string_view reply={})
static void MaybeDispatchRequestToWorker (std::shared_ptr< HTTPRequest > hreq)
static void RejectRequest (std::unique_ptr< HTTPRequest > hreq)
static std::vector< std::pair< std::string, uint16_t > > GetBindAddresses ()
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 (const std::string_view uri, const 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.
bilingual_str InvalidPortErrMsg (const std::string &optname, const std::string &invalid_value)

Variables

static constexpr auto SELECT_TIMEOUT {50ms}
static constexpr int SOCKET_OPTION_TRUE {1}
 Explicit alias for setting socket option methods.
static std::unique_ptr< HTTPServer > g_http_server {nullptr}
 HTTP module state.
static GlobalMutex g_httppathhandlers_mutex
 Handlers for (sub)paths.
static ThreadPool g_threadpool_http ("http")
 Http thread pool - future: encapsulate in HttpContext
static int g_max_queue_depth {100}

Function Documentation

◆ GetBindAddresses()

std::vector< std::pair< std::string, uint16_t > > GetBindAddresses ( )
static

Definition at line 208 of file httpserver.cpp.

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

◆ GetQueryParameterFromUri()

std::optional< std::string > GetQueryParameterFromUri ( const std::string_view uri,
const 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:

◆ GUARDED_BY()

std::vector< HTTPPathHandler > pathHandlers GUARDED_BY ( g_httppathhandlers_mutex )
static

◆ 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:

◆ InvalidPortErrMsg()

bilingual_str common::InvalidPortErrMsg ( const std::string & optname,
const std::string & invalid_value )

Definition at line 148 of file messages.cpp.

Here is the caller graph for this function:

◆ MaybeDispatchRequestToWorker()

void MaybeDispatchRequestToWorker ( std::shared_ptr< HTTPRequest > hreq)
static

Definition at line 136 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:

◆ RejectRequest()

void RejectRequest ( std::unique_ptr< HTTPRequest > hreq)
static

Definition at line 202 of file httpserver.cpp.

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

◆ RequestMethodString()

std::string_view RequestMethodString ( HTTPRequestMethod m)

HTTP request method as string - use for logging only.

Definition at line 117 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:

◆ WriteNoStoreErrorReply()

void WriteNoStoreErrorReply ( HTTPRequest & req,
HTTPStatusCode status,
std::string_view reply = {} )
static

Definition at line 130 of file httpserver.cpp.

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

Variable Documentation

◆ g_http_server

std::unique_ptr<HTTPServer> g_http_server {nullptr}
static

HTTP module state.

Definition at line 69 of file httpserver.cpp.

◆ g_httppathhandlers_mutex

GlobalMutex g_httppathhandlers_mutex
static

Handlers for (sub)paths.

Definition at line 71 of file httpserver.cpp.

◆ g_max_queue_depth

int g_max_queue_depth {100}
static

Definition at line 76 of file httpserver.cpp.

◆ g_threadpool_http

ThreadPool g_threadpool_http("http") ( "http" )
static

Http thread pool - future: encapsulate in HttpContext

◆ SELECT_TIMEOUT

auto SELECT_TIMEOUT {50ms}
staticconstexpr

The set of sockets cannot be modified while waiting, so the sleep time needs to be small to avoid new sockets stalling.

Definition at line 47 of file httpserver.cpp.

◆ SOCKET_OPTION_TRUE

int SOCKET_OPTION_TRUE {1}
staticconstexpr

Explicit alias for setting socket option methods.

Definition at line 50 of file httpserver.cpp.