| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for dpp::http_server:
[legend]

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

## Public Attributes

uint16_t | bound_port
| Port we are listening on.
event_handle | close_event
| Event to handle socket removal from the connection map.
std::unordered_map< socket, std::unique_ptr< http_server_request > > | connections
| Active connections for the server of type T.
cluster * | creator
| Cluster creator.
socket_events | events
| Socket events for listen socket in the socket engine.
raii_socket | fd
| The listening socket for incoming connections.
bool | plaintext
| True if plain text connections to the server are allowed.
std::string | private_key_file
| Private key PEM file path, if running an SSL server.
std::string | public_key_file
| Public key PEM file path, if running an SSL server.
http_server_request_event | request_handler
| Request handler callback to use for all incoming HTTP(S) requests.

## 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

  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

## ◆ ~http_server()

virtual dpp::http_server::~http_server | ( |  | ) |

inline virtual

Destructor.

## Member Function Documentation

## ◆ emplace()

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

override virtual

Emplace a new request into the connection pool.

Parameters

  newfd | file 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 )

inline virtual inherited

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

Parameters

  sfd | File descriptor for listening socket
  e | socket 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

raii_socket dpp::socket_listener< http_server_request, typename >::fd

inherited

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 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0