D++ (DPP)
C++ Discord API Bot Library
dpp::http_server Struct Reference

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...
 
void emplace (socket newfd) override
 Emplace a new request into the connection pool. More...
 
virtual ~http_server ()
 Destructor. 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

http_server_request_event request_handler
 Request handler callback to use for all incoming HTTP(S) requests. More...
 
uint16_t bound_port
 Port we are listening on. More...
 
raii_socket fd
 The listening socket for incoming connections. More...
 
std::unordered_map< socket, std::unique_ptr< http_server_request > > connections
 Active connections for the server of type T. More...
 
clustercreator
 Cluster creator. 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...
 
event_handle close_event
 Event to handle socket removal from the connection map. More...
 
socket_events events
 Socket events for listen socket in the socket engine. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ http_server()

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.

Parameters
creatorCluster creator
addressaddress to bind to, use "0.0.0.0" to bind to all local addresses
portport to bind to. You should generally use a port > 1024.
handle_requestCallback to call for each pending request
private_keyPrivate key PEM file for HTTPS/SSL. If empty, a plaintext server is created
public_keyPublic key PEM file for HTTPS/SSL. If empty, a plaintext server is created

◆ ~http_server()

virtual dpp::http_server::~http_server ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ emplace()

void dpp::http_server::emplace ( socket  newfd)
overridevirtual

Emplace a new request into the connection pool.

Parameters
newfdfile descriptor of new request

Implements dpp::socket_listener< http_server_request >.

◆ handle_accept()

virtual void dpp::socket_listener< http_server_request , typename >::handle_accept ( socket  sfd,
const struct socket_events e 
)
inlinevirtualinherited

Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid.

Parameters
sfdFile descriptor for listening socket
esocket events for the listening socket

Member Data Documentation

◆ bound_port

uint16_t dpp::http_server::bound_port

Port we are listening on.

◆ close_event

event_handle dpp::socket_listener< http_server_request , typename >::close_event
inherited

Event to handle socket removal from the connection map.

◆ connections

std::unordered_map<socket, std::unique_ptr<http_server_request > > dpp::socket_listener< http_server_request , typename >::connections
inherited

Active connections for the server of type T.

◆ creator

cluster* dpp::socket_listener< http_server_request , typename >::creator
inherited

Cluster creator.

◆ events

socket_events dpp::socket_listener< http_server_request , typename >::events
inherited

Socket events for listen socket in the socket engine.

◆ fd

The listening socket for incoming connections.

◆ plaintext

bool dpp::socket_listener< http_server_request , typename >::plaintext
inherited

True if plain text connections to the server are allowed.

◆ private_key_file

std::string dpp::socket_listener< http_server_request , typename >::private_key_file
inherited

Private key PEM file path, if running an SSL server.

◆ public_key_file

std::string dpp::socket_listener< http_server_request , typename >::public_key_file
inherited

Public key PEM file path, if running an SSL server.

◆ request_handler

http_server_request_event dpp::http_server::request_handler

Request handler callback to use for all incoming HTTP(S) requests.

D++ Library version 10.1.1D++ Library version 10.1.0D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0