staticlib_pion  2.0.2
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Friends | List of all members
staticlib::pion::http_server Class Reference

Server extension that supports streaming requests of arbitrary size (file upload) More...

#include <staticlib/pion/http_server.hpp>

Inheritance diagram for staticlib::pion::http_server:
staticlib::pion::tcp_server

Public Member Functions

 ~http_server () STATICLIB_NOEXCEPT
 http_server (uint32_t number_of_threads, uint16_t port, asio::ip::address_v4 ip_address=asio::ip::address_v4::any(), uint32_t read_timeout_millis=10000, const std::string &ssl_key_file=std::string(), std::function< std::string(std::size_t, asio::ssl::context::password_purpose)> ssl_key_password_callback=[](std::size_t, asio::ssl::context::password_purpose){return std::string();}, const std::string &ssl_verify_file=std::string(), std::function< bool(bool, asio::ssl::verify_context &)> ssl_verify_callback=[](bool, asio::ssl::verify_context &){return true;})
 Creates a new server object.
void add_handler (const std::string &method, const std::string &resource, request_handler_type request_handler)
 Adds a new web service to the HTTP server.
void set_bad_request_handler (request_handler_type handler)
 Sets the function that handles bad HTTP requests.
void set_not_found_handler (request_handler_type handler)
 Sets the function that handles requests which match no other web services.
void add_payload_handler (const std::string &method, const std::string &resource, payload_handler_creator_type payload_handler)
 Adds a new payload_handler to the HTTP server.
void add_websocket_handler (const std::string &event, const std::string &resource, websocket_handler_type handler)
 Adds a new handler for WebSocket events.
void broadcast_websocket (const std::string &path, sl::io::span< const char > message, sl::websocket::frame_type frame_type=sl::websocket::frame_type::text, const std::set< std::string > &dest_ids=std::set< std::string >())
 Broadcasts specified message to the WebSocket clients currently connected on the specified path.
- Public Member Functions inherited from staticlib::pion::tcp_server
 tcp_server (const asio::ip::tcp::endpoint &endpoint, uint32_t number_of_threads)
 Protected constructor so that only derived objects may be created.
 tcp_server (const tcp_server &)
 Deleted copy constructor.
tcp_server & operator= (const tcp_server &)
 Deleted copy assignment operator.
virtual ~tcp_server () STATICLIB_NOEXCEPT
 Virtual destructor.
void start ()
 Starts listening for new connections.
void stop (bool wait_until_finished=false)
 Stops listening for new connections.
bool is_listening () const
 Returns true if the server is listening for connections.
virtual void handle_connection (tcp_connection_ptr &tcp_conn)
 Handles a new TCP connection; derived classes SHOULD override this since the default behavior does nothing.
asio::io_service & get_io_service ()
 Returns an async I/O service used to schedule work.
scheduler & get_scheduler ()
 Return active scheduler.

Friends

class http_request_reader

Additional Inherited Members

- Protected Attributes inherited from staticlib::pion::tcp_server
scheduler active_scheduler
 Reference to the active scheduler object used to manage worker threads.
asio::ip::tcp::acceptor tcp_acceptor
 Manages async TCP connections.
tcp_connection::ssl_context_type ssl_context
 Context used for SSL configuration.
std::condition_variable server_has_stopped
 Condition triggered when the server has stopped listening for connections.
std::condition_variable no_more_connections
 Condition triggered when the connection pool is empty.
std::set< tcp_connection_ptr > conn_pool
 Pool of active connections associated with this server.
asio::ip::tcp::endpoint tcp_endpoint
 TCP endpoint used to listen for new connections.
bool ssl_flag
 true if the server uses SSL to encrypt connections
bool listening
 Set to true when the server is listening for new connections.
std::mutex mutex
 Mutex to make class thread-safe.

Detailed Description

Server extension that supports streaming requests of arbitrary size (file upload)

Constructor & Destructor Documentation

staticlib::pion::http_server::~http_server ( )
inline
staticlib::pion::http_server::http_server ( uint32_t  number_of_threads,
uint16_t  port,
asio::ip::address_v4  ip_address = asio::ip::address_v4::any(),
uint32_t  read_timeout_millis = 10000,
const std::string &  ssl_key_file = std::string() 
)

Creates a new server object.

Parameters
number_of_threadsnumber of threads to use for requests processing
portTCP port
read_timeout_millistimeout for read operations
ip_address(optional) IPv4-address to use, ANY address by default
ssl_key_file(optional) path file containing concatenated X.509 key and certificate, empty by default (SSL disabled)
ssl_key_password_callback(optional) callback function that should return a password that will be used to decrypt a PEM-encoded RSA private key file
ssl_verify_file(optional) path to file containing one or more CA certificates in PEM format
ssl_verify_callback(optional) callback function that can be used to customize client certificate auth

Member Function Documentation

void staticlib::pion::http_server::add_handler ( const std::string &  method,
const std::string &  resource,
request_handler_type  request_handler 
)

Adds a new web service to the HTTP server.

Parameters
methodHTTP method name
resourcethe resource name or uri-stem to bind to the handler
request_handlerfunction used to handle requests to the resource
void staticlib::pion::http_server::add_payload_handler ( const std::string &  method,
const std::string &  resource,
payload_handler_creator_type  payload_handler 
)

Adds a new payload_handler to the HTTP server.

Parameters
methodHTTP method name
resourcethe resource name or uri-stem to bind to the handler
payload_handlerfunction used to handle payload for the request
void staticlib::pion::http_server::add_websocket_handler ( const std::string &  event,
const std::string &  resource,
websocket_handler_type  handler 
)

Adds a new handler for WebSocket events.

Parameters
eventWebSocket event name
resourcethe resource name or uri-stem to bind to the handler
handlerfunction used to handle WebSocket events
void staticlib::pion::http_server::broadcast_websocket ( const std::string &  path,
sl::io::span< const char >  message,
sl::websocket::frame_type  frame_type = sl::websocket::frame_type::text,
const std::set< std::string > &  dest_ids = std::set< std::string >() 
)

Broadcasts specified message to the WebSocket clients currently connected on the specified path.

Parameters
pathwebsocket path clients connected on
messagemessage to broadcast
frame_typetype of the websocket frame to use, text by default
dest_idsbroadcast only to the specified list of ids, broadcast to all clients on the specified path by default
void staticlib::pion::http_server::set_bad_request_handler ( request_handler_type  handler)
inline

Sets the function that handles bad HTTP requests.

Parameters
handlerfunction that handles bad HTTP requests
void staticlib::pion::http_server::set_not_found_handler ( request_handler_type  handler)
inline

Sets the function that handles requests which match no other web services.

Parameters
handlerfunction that handles requests which match no other web services

Friends And Related Function Documentation

friend class http_request_reader
friend

The documentation for this class was generated from the following file: