![]() |
D++ (DPP)
C++ Discord API Bot Library
|
Creates a simple HTTP server which listens on a TCP port for a plaintext or SSL incoming request, and passes that request to a callback to generate the response. More...
#include <http_server.h>
Inheritance diagram for dpp::http_server:
Collaboration diagram for dpp::http_server:Public Member Functions | |
| http_server (cluster *creator, const std::string_view address, uint16_t port, http_server_request_event handle_request, const std::string &private_key="", const std::string &public_key="") | |
| Constructor for creation of a HTTP(S) server. More... | |
| virtual | ~http_server () |
| Destructor. More... | |
| void | emplace (socket newfd) override |
| Emplace a new request into the connection pool. More... | |
| virtual void | handle_accept (socket sfd, const struct socket_events &e) |
| Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid. More... | |
Public Attributes | |
| uint16_t | bound_port |
| Port we are listening on. More... | |
| event_handle | close_event |
| Event to handle socket removal from the connection map. More... | |
| std::unordered_map< socket, std::unique_ptr< http_server_request > > | connections |
| Active connections for the server of type T. More... | |
| cluster * | creator |
| Cluster creator. More... | |
| socket_events | events |
| Socket events for listen socket in the socket engine. More... | |
| raii_socket | fd |
| The listening socket for incoming connections. More... | |
| bool | plaintext |
| True if plain text connections to the server are allowed. More... | |
| std::string | private_key_file |
| Private key PEM file path, if running an SSL server. More... | |
| std::string | public_key_file |
| Public key PEM file path, if running an SSL server. More... | |
| http_server_request_event | request_handler |
| Request handler callback to use for all incoming HTTP(S) requests. More... | |
Creates a simple HTTP server which listens on a TCP port for a plaintext or SSL incoming request, and passes that request to a callback to generate the response.
| dpp::http_server::http_server | ( | cluster * | creator, |
| const std::string_view | address, | ||
| uint16_t | port, | ||
| http_server_request_event | handle_request, | ||
| const std::string & | private_key = "", |
||
| const std::string & | public_key = "" |
||
| ) |
Constructor for creation of a HTTP(S) server.
| creator | Cluster creator |
| address | address to bind to, use "0.0.0.0" to bind to all local addresses |
| port | port to bind to. You should generally use a port > 1024. |
| handle_request | Callback to call for each pending request |
| private_key | Private key PEM file for HTTPS/SSL. If empty, a plaintext server is created |
| public_key | Public key PEM file for HTTPS/SSL. If empty, a plaintext server is created |
|
inlinevirtual |
Destructor.
|
overridevirtual |
Emplace a new request into the connection pool.
| newfd | file descriptor of new request |
Implements dpp::socket_listener< http_server_request >.
|
inlinevirtualinherited |
Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid.
| sfd | File descriptor for listening socket |
| e | socket events for the listening socket |
| uint16_t dpp::http_server::bound_port |
Port we are listening on.
|
inherited |
Event to handle socket removal from the connection map.
|
inherited |
Active connections for the server of type T.
|
inherited |
Cluster creator.
|
inherited |
Socket events for listen socket in the socket engine.
|
inherited |
The listening socket for incoming connections.
|
inherited |
True if plain text connections to the server are allowed.
|
inherited |
Private key PEM file path, if running an SSL server.
|
inherited |
Public key PEM file path, if running an SSL server.
| http_server_request_event dpp::http_server::request_handler |
Request handler callback to use for all incoming HTTP(S) requests.