Bitcoin Core 32.99.0
P2P Digital Currency
httpserver.h
Go to the documentation of this file.
1// Copyright (c) 2015-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_HTTPSERVER_H
6#define BITCOIN_HTTPSERVER_H
7
8#include <atomic>
9#include <functional>
10#include <memory>
11#include <optional>
12#include <span>
13#include <stdexcept>
14#include <string>
15#include <vector>
16
17#include <netaddress.h>
18#include <rpc/protocol.h>
19#include <util/byte_units.h>
20#include <util/expected.h>
21#include <util/sock.h>
22#include <util/strencodings.h>
23#include <util/string.h>
24#include <util/threadinterrupt.h>
25#include <util/time.h>
26
27namespace util {
28class SignalInterrupt;
29} // namespace util
30
34inline constexpr int DEFAULT_HTTP_THREADS=16;
35
40inline constexpr int DEFAULT_HTTP_WORKQUEUE=64;
41
42inline constexpr int DEFAULT_HTTP_SERVER_TIMEOUT=30;
43
47inline constexpr int DEFAULT_MAX_HTTP_CONNECTIONS = 16;
48
50 UNKNOWN,
51 GET,
52 POST,
53 HEAD,
54 PUT
55};
56
57class HTTPRequest;
58
60using HTTPRequestHandler = std::function<void(HTTPRequest* req, const std::string&)>;
61
66void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler);
68void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch);
69
70namespace bitcoin_http {
72inline constexpr size_t MIN_REQUEST_LINE_LENGTH = std::string_view("GET / HTTP/1.0").size();
73
78inline constexpr size_t MAX_HEADERS_SIZE{8192};
79
82inline constexpr uint64_t MAX_BODY_SIZE{32_MiB};
83
86struct ContentTooLargeError : std::runtime_error {
87 using std::runtime_error::runtime_error;
88};
89} // namespace bitcoin_http
90
92{
93public:
99 std::optional<std::string> FindFirst(std::string_view key) const;
104 std::vector<std::string_view> FindAll(std::string_view key) const LIFETIMEBOUND;
105 void Write(std::string&& key, std::string&& value);
109 void RemoveAll(std::string_view key);
119 bool Read(util::LineReader& reader, bool write = true);
120 std::string Stringify() const;
121
122private:
127 std::vector<std::pair<std::string, std::string>> m_headers;
128
130 size_t m_consumed{0};
131};
132
139 uint8_t major{1};
140 uint8_t minor{1};
142};
143
144struct HTTPResponse {
148
149 std::string StringifyHeaders() const;
150};
151
152class HTTPRemoteClient;
153
155{
156public:
157 explicit HTTPRequest(const std::shared_ptr<HTTPRemoteClient>& client) : m_client{client} {}
159 explicit HTTPRequest() : m_client{} {}
160
174
175 void WriteReply(HTTPStatusCode status, std::span<const std::byte> reply_body = {});
176 void WriteReply(HTTPStatusCode status, std::string_view reply_body_view)
177 {
178 WriteReply(status, std::as_bytes(std::span{reply_body_view}));
179 }
180
182 std::shared_ptr<HTTPRemoteClient> GetClient() const { return m_client.lock(); }
183
184 // These methods reimplement the API from http_libevent::HTTPRequest
185 // for downstream JSONRPC and REST modules.
186 std::string GetURI() const { return m_target; }
187 CService GetPeer() const;
189 std::optional<std::string> GetQueryParameter(std::string_view key) const;
190 std::optional<std::string> GetHeader(std::string_view hdr) const;
191 std::string ReadBody() const { return m_body; }
192 void WriteHeader(std::string&& hdr, std::string&& value);
193 std::optional<uint64_t> GetChunkSize() const { return m_chunk_size; }
194 uint64_t GetChunkProgress() const { return m_chunk_read; }
195
196 enum class State {
197 Init,
198 NeedsHeaders,
199 NeedsBody,
200 Complete,
201 Error
202 };
203 State GetState() const { return m_state; }
204 void SetState(State state) { m_state = state; }
205
206private:
208 std::string m_target;
211 std::string m_body;
212
214 std::weak_ptr<HTTPRemoteClient> m_client;
215
218
219 // If a large request is sent with "Transfer-encoding: chunked" we may
220 // read the chunk size in a separate I/O loop iteration than the chunk
221 // of data itself. Store the chunk size value here until the chunk is read.
222 std::optional<uint64_t> m_chunk_size;
223 // We may also read a large chunk over multiple loop iterations.
224 // Track the progress of the chunk here.
225 uint64_t m_chunk_read{0};
226
228};
229
231{
232public:
236 using Id = uint64_t;
237
238 explicit HTTPServer(std::function<void(std::unique_ptr<HTTPRequest>&&)> func)
239 : m_request_dispatcher{std::move(func)} {}
240
241 virtual ~HTTPServer()
242 {
243 Assume(!m_thread_socket_handler.joinable()); // Missing call to JoinSocketsThreads()
244 Assume(m_connected.empty()); // Missing call to DisconnectClients(), or disconnect flags not set
245 Assume(m_listen.empty()); // Missing call to StopListening()
246 }
247
251 bool InitHTTPAllowList();
252
259
263 void StopListening();
264
268 size_t GetListeningSocketCount() const { return m_listen.size(); }
269
273 size_t GetConnectionsCount() const { return m_connected_size.load(std::memory_order_acquire); }
274
278 void StartSocketsThreads();
279
283 void JoinSocketsThreads();
284
289
294
299 void SetRequestHandler(std::function<void(std::unique_ptr<HTTPRequest>&&)> func)
301 {
303 m_request_dispatcher = std::move(func));
304 }
305
313
317 void SetServerTimeout(std::chrono::seconds seconds) { m_rpcservertimeout = seconds; }
318
322 void SetMaxConnections(int max_conn) { m_rpcmaxconnections = max_conn; }
323
329
330private:
334 std::vector<std::shared_ptr<Sock>> m_listen;
335
339 std::atomic<Id> m_next_id{0};
340
347 std::vector<std::shared_ptr<HTTPRemoteClient>> m_connected;
348
353 std::atomic_bool m_stop_accepting{false};
354
360 std::atomic_bool m_disconnect_all_clients{false};
361
367 std::atomic<size_t> m_connected_size{0};
368
373 struct IOReadiness {
380
386 std::unordered_map<Sock::EventsPerSock::key_type,
387 std::shared_ptr<HTTPRemoteClient>,
391 };
392
397
403
404 /*
405 * What to do with HTTP requests once received, validated and parsed.
406 * Set in main thread by server start and interrupt but read in
407 * worker threads.
408 */
411 std::function<void(std::unique_ptr<HTTPRequest>&&)> m_request_dispatcher GUARDED_BY(m_request_dispatcher_mutex);
413
418
422 std::vector<CSubNet> m_allow_subnets;
423
427 bool ClientAllowed(const CNetAddr& netaddr) const;
428
433
440 std::unique_ptr<Sock> AcceptConnection(const Sock& listen_sock, CService& addr);
441
445 Id GetNewId();
446
453 void NewSockAccepted(std::unique_ptr<Sock>&& sock, const CService& addr);
454
459 void SocketHandlerConnected(const IOReadiness& io_readiness) const
461
466 void SocketHandlerListening(const Sock::EventsPerSock& events_per_sock);
467
473 IOReadiness GenerateWaitSockets() const;
474
480
487 void DisconnectClients();
488};
489
490std::optional<std::string> GetQueryParameterFromUri(std::string_view uri, std::string_view key);
491
493{
494public:
495 explicit HTTPRemoteClient(HTTPServer::Id id, const CService& addr, std::unique_ptr<Sock> socket)
496 : m_id(id), m_addr(addr), m_origin(addr.ToStringAddrPort()), m_sock{std::move(socket)}, m_idle_since{Now<SteadySeconds>()} {}
497
498 // Disable copies (should only be used as shared pointers)
501
502 const std::string& GetOrigin() const LIFETIMEBOUND { return m_origin; }
503 const CService& GetPeer() const LIFETIMEBOUND { return m_addr; }
504 std::shared_ptr<Sock> GetSock() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex) { return WITH_LOCK(m_sock_mutex, return m_sock;); }
505 bool ReadyToSend() const EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex) { return WITH_LOCK(m_send_mutex, return m_send_ready;); }
506 bool ReceiveBufferEmpty() const { return m_recv_buffer.empty(); }
507
508 void Send(const HTTPResponse& res, std::span<const std::byte> reply_body, bool keep_alive) EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex, !m_sock_mutex);
509 void Receive() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
510
511 bool MaybeDisconnect(std::chrono::time_point<SteadyClock> now, std::chrono::seconds rpcservertimeout, bool disconnect_all);
512
519 static std::unique_ptr<HTTPRequest> TryReadRequest(const std::shared_ptr<HTTPRemoteClient>& client) EXCLUSIVE_LOCKS_REQUIRED(!client->m_send_mutex);
520
525 bool MaybeSendBytesFromBuffer() EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex, !m_sock_mutex);
526
532 const HTTPRequest* GetRequest() const LIFETIMEBOUND { return m_req.get(); }
533
535 const std::string& GetRecvBuffer() const LIFETIMEBOUND { return m_recv_buffer; }
536
537protected:
539 std::string& MutateRecvBuffer() { return m_recv_buffer; }
540
541private:
548 void ReadRequest(HTTPRequest& req);
549
552
555
557 const std::string m_origin;
558
564 std::string m_recv_buffer{};
565
569 std::unique_ptr<HTTPRequest> m_req;
570
574 std::atomic_bool m_req_busy{false};
575
582 std::vector<std::byte> m_send_buffer GUARDED_BY(m_send_mutex);
584
593 bool m_send_ready GUARDED_BY(m_send_mutex){false};
594
601
609 std::shared_ptr<Sock> m_sock GUARDED_BY(m_sock_mutex);
610
617 std::atomic_bool m_connection_busy{true};
618
622 std::atomic_bool m_keep_alive{false};
623
629 std::atomic_bool m_disconnect{false};
630
634 std::atomic<SteadySeconds> m_idle_since;
635};
636
640bool InitHTTPServer();
641
646void StartHTTPServer();
647
650
652void StopHTTPServer();
653
654#endif // BITCOIN_HTTPSERVER_H
#define LIFETIMEBOUND
Definition: attributes.h:16
#define Assume(val)
Assume is the identity function.
Definition: check.h:128
Network address.
Definition: netaddress.h:113
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:531
A helper class for interruptible sleeps.
std::optional< std::string > FindFirst(std::string_view key) const
Definition: httpserver.cpp:265
size_t m_consumed
Track total bytes consumed in Read() for limit checks.
Definition: httpserver.h:130
void RemoveAll(std::string_view key)
Definition: httpserver.cpp:291
std::vector< std::pair< std::string, std::string > > m_headers
Headers can have duplicate field names, so we use a vector of key-value pairs instead of a map.
Definition: httpserver.h:127
bool Read(util::LineReader &reader, bool write=true)
Definition: httpserver.cpp:299
std::string Stringify() const
Definition: httpserver.cpp:355
void Write(std::string &&key, std::string &&value)
Definition: httpserver.cpp:286
std::vector< std::string_view > FindAll(std::string_view key) const LIFETIMEBOUND
Definition: httpserver.cpp:275
bool ReceiveBufferEmpty() const
Definition: httpserver.h:506
bool m_send_ready GUARDED_BY(m_send_mutex)
Set true by worker threads after writing a response to m_send_buffer.
Definition: httpserver.h:593
std::vector< std::byte > m_send_buffer GUARDED_BY(m_send_mutex)
Mutex m_send_mutex
Response data destined for this client.
Definition: httpserver.h:581
std::string & MutateRecvBuffer()
Used for tests.
Definition: httpserver.h:539
bool ReadyToSend() const EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex)
Definition: httpserver.h:505
const std::string m_origin
IP:port of connected client, cached for logging purposes.
Definition: httpserver.h:557
const HTTPServer::Id m_id
ID provided by HTTPServer upon connection and instantiation.
Definition: httpserver.h:551
HTTPRemoteClient(HTTPServer::Id id, const CService &addr, std::unique_ptr< Sock > socket)
Definition: httpserver.h:495
std::shared_ptr< Sock > m_sock GUARDED_BY(m_sock_mutex)
Underlying socket.
std::shared_ptr< Sock > GetSock() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex)
Definition: httpserver.h:504
std::atomic< SteadySeconds > m_idle_since
Timestamp of last send or receive activity, used for -rpcservertimeout.
Definition: httpserver.h:634
std::unique_ptr< HTTPRequest > m_req
Requests from a client must be processed in the order in which they were received,...
Definition: httpserver.h:569
Mutex m_sock_mutex
Mutex that serializes the Send() and Recv() calls on m_sock.
Definition: httpserver.h:600
const CService m_addr
Remote address of connected client.
Definition: httpserver.h:554
HTTPRemoteClient(const HTTPRemoteClient &)=delete
const CService & GetPeer() const LIFETIMEBOUND
Definition: httpserver.h:503
const std::string & GetOrigin() const LIFETIMEBOUND
Definition: httpserver.h:502
HTTPRemoteClient & operator=(const HTTPRemoteClient &)=delete
const std::string & GetRecvBuffer() const LIFETIMEBOUND
Used for tests.
Definition: httpserver.h:535
void WriteHeader(std::string &&hdr, std::string &&value)
Definition: httpserver.cpp:703
std::optional< uint64_t > m_chunk_size
Definition: httpserver.h:222
std::optional< std::string > GetQueryParameter(std::string_view key) const
Definition: httpserver.cpp:666
std::string GetURI() const
Definition: httpserver.h:186
State m_state
Definition: httpserver.h:227
std::string m_target
Definition: httpserver.h:208
bool LoadHeaders(util::LineReader &reader)
Definition: httpserver.cpp:426
HTTPHeaders m_headers
Definition: httpserver.h:210
void WriteReply(HTTPStatusCode status, std::string_view reply_body_view)
Definition: httpserver.h:176
bool LoadControlData(util::LineReader &reader)
Methods that attempt to parse HTTP request fields line-by-line from a receive buffer.
Definition: httpserver.cpp:378
HTTPVersion m_version
Definition: httpserver.h:209
uint64_t m_chunk_read
Definition: httpserver.h:225
std::weak_ptr< HTTPRemoteClient > m_client
Pointer to the client that made the request so we know who to respond to.
Definition: httpserver.h:214
std::optional< std::string > GetHeader(std::string_view hdr) const
Definition: httpserver.cpp:698
HTTPRequest()
Construct with a null client for unit tests.
Definition: httpserver.h:159
HTTPRequestMethod m_method
Definition: httpserver.h:207
std::shared_ptr< HTTPRemoteClient > GetClient() const
Definition: httpserver.h:182
HTTPRequestMethod GetRequestMethod() const
Definition: httpserver.h:188
std::string m_body
Definition: httpserver.h:211
std::string ReadBody() const
Definition: httpserver.h:191
HTTPRequest(const std::shared_ptr< HTTPRemoteClient > &client)
Definition: httpserver.h:157
bool LoadBody(util::LineReader &reader)
Definition: httpserver.cpp:431
uint64_t GetChunkProgress() const
Definition: httpserver.h:194
void SetState(State state)
Definition: httpserver.h:204
void WriteReply(HTTPStatusCode status, std::span< const std::byte > reply_body={})
Definition: httpserver.cpp:535
State GetState() const
Definition: httpserver.h:203
CService GetPeer() const
Definition: httpserver.cpp:657
const HTTPVersion & GetVersion() const LIFETIMEBOUND
Definition: httpserver.h:181
std::optional< uint64_t > GetChunkSize() const
Definition: httpserver.h:193
HTTPHeaders m_response_headers
Response headers may be set in advance before response body is known.
Definition: httpserver.h:217
std::atomic< Id > m_next_id
The id to assign to the next created connection.
Definition: httpserver.h:339
HTTPServer(std::function< void(std::unique_ptr< HTTPRequest > &&)> func)
Definition: httpserver.h:238
void ThreadSocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_request_dispatcher_mutex)
Check connected and listening sockets for IO readiness and process them accordingly.
void JoinSocketsThreads()
Join (wait for) the threads started by StartSocketsThreads() to exit.
Definition: httpserver.cpp:813
std::function< void(std::unique_ptr< HTTPRequest > &&)> m_request_dispatcher GUARDED_BY(m_request_dispatcher_mutex)
void InterruptNet()
Stop network activity.
Definition: httpserver.h:288
std::vector< std::shared_ptr< HTTPRemoteClient > > m_connected
List of HTTPRemoteClients with connected sockets.
Definition: httpserver.h:347
int m_rpcmaxconnections
Maximum amount of concurrent connections.
Definition: httpserver.h:432
void StopAccepting()
Stop accepting new connections in the I/O loop.
Definition: httpserver.h:312
CThreadInterrupt m_interrupt_net
This is signaled when network activity should cease.
Definition: httpserver.h:396
void SocketHandlerConnected(const IOReadiness &io_readiness) const EXCLUSIVE_LOCKS_REQUIRED(!m_request_dispatcher_mutex)
Do the read/write for connected sockets that are ready for IO.
Definition: httpserver.cpp:890
std::atomic_bool m_disconnect_all_clients
Flag used during shutdown.
Definition: httpserver.h:360
Id GetNewId()
Generate an id for a newly created connection.
Definition: httpserver.cpp:858
void SetMaxConnections(int max_conn)
Set the maximum amount of connected HTTPClients (-rpcmaxconnections)
Definition: httpserver.h:322
void DisconnectClients()
Close underlying socket connections for flagged clients by removing their shared pointer from m_conne...
util::Expected< void, std::string > BindAndStartListening(const CService &to)
Bind to a new address:port, start listening and add the listen socket to m_listen.
Definition: httpserver.cpp:708
std::vector< CSubNet > m_allow_subnets
List of subnets to allow HTTP connections from.
Definition: httpserver.h:422
void ClearConnectedClients()
Force-remove all remaining clients from m_connected without waiting for graceful disconnection.
std::atomic< size_t > m_connected_size
The number of connected sockets.
Definition: httpserver.h:367
std::vector< std::shared_ptr< Sock > > m_listen
List of listening sockets.
Definition: httpserver.h:334
std::atomic_bool m_stop_accepting
Flag used during shutdown to stop accepting new connections.
Definition: httpserver.h:353
void SocketHandlerListening(const Sock::EventsPerSock &events_per_sock)
Accept incoming connections, one from each read-ready listening socket.
Definition: httpserver.cpp:972
IOReadiness GenerateWaitSockets() const
Generate a collection of sockets to check for IO readiness.
Definition: httpserver.cpp:994
std::thread m_thread_socket_handler
Thread that sends to and receives from sockets and accepts connections.
Definition: httpserver.h:402
uint64_t Id
Each connection is assigned an unique id of this type.
Definition: httpserver.h:236
std::chrono::seconds m_rpcservertimeout
Idle timeout after which clients are disconnected.
Definition: httpserver.h:417
void SetServerTimeout(std::chrono::seconds seconds)
Set the idle client timeout (-rpcservertimeout)
Definition: httpserver.h:317
void StopListening()
Stop listening by closing all listening sockets.
Definition: httpserver.cpp:796
size_t GetConnectionsCount() const
Get the number of HTTPRemoteClients we are connected to.
Definition: httpserver.h:273
void NewSockAccepted(std::unique_ptr< Sock > &&sock, const CService &addr)
After a new socket with a client has been created, configure its flags, make a new HTTPRemoteClient a...
Definition: httpserver.cpp:863
void SetRequestHandler(std::function< void(std::unique_ptr< HTTPRequest > &&)> func) EXCLUSIVE_LOCKS_REQUIRED(!m_request_dispatcher_mutex)
Update the request handler method.
Definition: httpserver.h:299
virtual ~HTTPServer()
Definition: httpserver.h:241
bool ClientAllowed(const CNetAddr &netaddr) const
Check an incoming connection's source IP against the allow list.
Definition: httpserver.cpp:79
size_t GetListeningSocketCount() const
Get the number of sockets the server is bound to and listening on.
Definition: httpserver.h:268
bool InitHTTPAllowList()
Parse the user's -rpcallowip settings and populate m_allow_subnets.
Definition: httpserver.cpp:90
void DisconnectAllClients()
Start disconnecting clients when possible in the I/O loop.
Definition: httpserver.h:293
Mutex m_request_dispatcher_mutex
Definition: httpserver.h:410
std::unique_ptr< Sock > AcceptConnection(const Sock &listen_sock, CService &addr)
Accept a connection.
Definition: httpserver.cpp:820
void StartSocketsThreads()
Start the necessary threads for sockets IO.
Definition: httpserver.cpp:801
Definition: init.h:13
RAII helper class that manages a socket and closes it automatically when it goes out of scope.
Definition: sock.h:35
std::unordered_map< std::shared_ptr< const Sock >, Events, HashSharedPtrSock, EqualSharedPtrSock > EventsPerSock
On which socket to wait for what events in WaitMany().
Definition: sock.h:216
The util::Expected class provides a standard way for low-level functions to return either error value...
Definition: expected.h:44
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
void InterruptHTTPServer()
Interrupt HTTP server threads.
constexpr int DEFAULT_MAX_HTTP_CONNECTIONS
Maximum number of connected HTTP clients.
Definition: httpserver.h:47
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
Definition: httpserver.cpp:248
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
Definition: httpserver.cpp:241
std::function< void(HTTPRequest *req, const std::string &)> HTTPRequestHandler
Handler for requests to a certain HTTP path.
Definition: httpserver.h:60
void StartHTTPServer()
Start HTTP server.
constexpr int DEFAULT_HTTP_SERVER_TIMEOUT
Definition: httpserver.h:42
bool InitHTTPServer()
Initialize HTTP server.
constexpr int DEFAULT_HTTP_THREADS
The default value for -rpcthreads.
Definition: httpserver.h:34
constexpr int DEFAULT_HTTP_WORKQUEUE
The default value for -rpcworkqueue.
Definition: httpserver.h:40
HTTPRequestMethod
Definition: httpserver.h:49
void StopHTTPServer()
Stop HTTP server.
std::optional< std::string > GetQueryParameterFromUri(std::string_view uri, std::string_view key)
Definition: httpserver.cpp:673
util::LineReader reader
std::unique_ptr< ProxyClient< messages::FooInterface > > client
std::thread thread
Thread variable should be after other struct members so the thread does not start until the other mem...
constexpr uint64_t MAX_BODY_SIZE
Maximum size of an HTTP request body received from a client.
Definition: httpserver.h:82
constexpr size_t MIN_REQUEST_LINE_LENGTH
Shortest valid request line, used by libevent in evhttp_parse_request_line()
Definition: httpserver.h:72
constexpr size_t MAX_HEADERS_SIZE
Maximum size of each headers line in an HTTP request, also the maximum size of all headers total.
Definition: httpserver.h:78
const char * prefix
Definition: rest.cpp:1197
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:1198
HTTPStatusCode
HTTP status codes.
Definition: protocol.h:13
@ HTTP_INTERNAL_SERVER_ERROR
Definition: protocol.h:22
HTTPVersion version
Definition: httpserver.h:145
std::string StringifyHeaders() const
Definition: httpserver.cpp:368
HTTPHeaders headers
Definition: httpserver.h:147
Info about which socket has which event ready and a reverse map back to the HTTPRemoteClient that own...
Definition: httpserver.h:373
std::unordered_map< Sock::EventsPerSock::key_type, std::shared_ptr< HTTPRemoteClient >, Sock::HashSharedPtrSock, Sock::EqualSharedPtrSock > httpclients_per_sock
Map of socket -> HTTPRemoteClient.
Definition: httpserver.h:390
Sock::EventsPerSock events_per_sock
Map of socket -> socket events.
Definition: httpserver.h:379
uint8_t minor
Definition: httpserver.h:140
uint8_t major
Default HTTP protocol version 1.1 is used by error responses when a request is unreadable.
Definition: httpserver.h:139
Thrown when a request body exceeds MAX_BODY_SIZE (or will exceed, in chunked transfer) so the server ...
Definition: httpserver.h:86
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:299
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
std::chrono::steady_clock SteadyClock
Definition: time.h:37
T Now()
Return the current time point cast to the given precision.
Definition: time.h:127
std::chrono::time_point< std::chrono::steady_clock, std::chrono::seconds > SteadySeconds
Definition: time.h:38