Header Only Library
HTTP Server
How to use HTTP server class
References
#include "IP/InternetProtocol.hpp"
Syntax
Example code
Variables
EVerb
FRequest
FResponse
Functions
Set Socket
- Set the
adress
,port
,max connection
of socket acceptor
Get Acceptor
- Get socket acceptor
Get Sockets
- Get all sockets connected to the server
Set Headers
- Set response default headers
Get Headers
- Return a reference to response default headers
- Use this function to modify or append value to headers
Send Response
- Send response to specific socket
- Return false if socket is closed
- Warning: If you’re using Windows, ensure that you are sending characters compatible with UTF-8
Send Response Error
- Send response error to specific socket
- Return false if socket is closed
- Warning: If you’re using Windows, ensure that you are sending characters compatible with UTF-8
Open
- Open connection
- Return false if socket is already open or any error occurs
- Event
on_error
is triggered if any error occurs
Close
- Close connection or cancel request
Disconnect Socket
- Close connection of specific socket
Get Error Code
- Get latest error code
Events
On Socket Accepted
- Event triggered when payload process has been finished
On Bytes Transfered
- Event triggered while the request is in progress
size_t
: bytes sentsize_t
: bytes received
On Request Received
- Event triggered when request has been received
FRequest
: Client request structFResponse
: Response struct
On Request Error
- Event triggered when request fail
FResponse
: Response struct
On Response Sent
- Event triggered when a response is sent to a specific socket
const asio::error_code &
: if error occur, error code will be different from 0
On Close
- Event triggered when socket is closed
On Error
- Event triggered if any error occur during async process
const asio::error_code &
: if error occur, error code will be different from 0- Normally, when an error occurs, the socket is automatically closed, triggering the
on_close
event.