Web server class.
More...
#include <Server.hpp>
|
using | OnConnectCheck = std::function<std::expected<void, Response>(Connection const&)> |
| Check to perform for each new client connection. The check takes client ip as input and returns a Response if the check failed. Response will be sent to the client and the connection will be closed.
|
|
using | OnDisconnectHook = impl::ConnectionHandler::OnDisconnectHook |
| Hook called when any connection disconnects.
|
|
|
| Server (boost::asio::io_context &ctx, boost::asio::ip::tcp::endpoint endpoint, std::optional< boost::asio::ssl::context > sslContext, ProcessingPolicy processingPolicy, std::optional< size_t > parallelRequestLimit, util::TagDecoratorFactory tagDecoratorFactory, std::optional< size_t > maxSubscriptionSendQueueSize, OnConnectCheck onConnectCheck, OnDisconnectHook onDisconnectHook) |
| Construct a new Server object.
|
|
| Server (Server const &)=delete |
| Copy constructor is deleted. The Server couldn't be copied.
|
|
| Server (Server &&)=default |
| Move constructor is defaulted.
|
|
void | onGet (std::string const &target, MessageHandler handler) |
| Set handler for GET requests.
|
|
void | onPost (std::string const &target, MessageHandler handler) |
| Set handler for POST requests.
|
|
void | onWs (MessageHandler handler) |
| Set handler for WebSocket requests.
|
|
std::optional< std::string > | run () |
| Run the server.
|
|
void | stop (boost::asio::yield_context yield) |
| Stop the server. This method will asynchronously sleep unless all the users are disconnected.
|
|
◆ Server()
web::ng::Server::Server |
( |
boost::asio::io_context & | ctx, |
|
|
boost::asio::ip::tcp::endpoint | endpoint, |
|
|
std::optional< boost::asio::ssl::context > | sslContext, |
|
|
ProcessingPolicy | processingPolicy, |
|
|
std::optional< size_t > | parallelRequestLimit, |
|
|
util::TagDecoratorFactory | tagDecoratorFactory, |
|
|
std::optional< size_t > | maxSubscriptionSendQueueSize, |
|
|
OnConnectCheck | onConnectCheck, |
|
|
OnDisconnectHook | onDisconnectHook ) |
Construct a new Server object.
- Parameters
-
ctx | The boost::asio::io_context to use. |
endpoint | The endpoint to listen on. |
sslContext | The SSL context to use (optional). |
processingPolicy | The requests processing policy (parallel or sequential). |
parallelRequestLimit | The limit of requests for one connection that can be processed in parallel. Only used if processingPolicy is parallel. |
tagDecoratorFactory | The tag decorator factory. |
maxSubscriptionSendQueueSize | The maximum size of the subscription send queue. |
onConnectCheck | The check to perform on each connection. |
onDisconnectHook | The hook to call on each disconnection. |
◆ onGet()
void web::ng::Server::onGet |
( |
std::string const & | target, |
|
|
MessageHandler | handler ) |
Set handler for GET requests.
- Note
- This method can't be called after run() is called.
- Parameters
-
target | The target of the request. |
handler | The handler to set. |
◆ onPost()
void web::ng::Server::onPost |
( |
std::string const & | target, |
|
|
MessageHandler | handler ) |
Set handler for POST requests.
- Note
- This method can't be called after run() is called.
- Parameters
-
target | The target of the request. |
handler | The handler to set. |
◆ onWs()
void web::ng::Server::onWs |
( |
MessageHandler | handler | ) |
|
Set handler for WebSocket requests.
- Note
- This method can't be called after run() is called.
- Parameters
-
handler | The handler to set. |
◆ run()
std::optional< std::string > web::ng::Server::run |
( |
| ) |
|
Run the server.
- Returns
- std::nullopt if the server started successfully, otherwise an error message.
◆ stop()
void web::ng::Server::stop |
( |
boost::asio::yield_context | yield | ) |
|
Stop the server. This method will asynchronously sleep unless all the users are disconnected.
- Note
- Stopping the server cause graceful shutdown of all connections. And rejecting new connections.
- Parameters
-
yield | The coroutine context. |
The documentation for this class was generated from the following files:
- /__w/clio/clio/src/web/ng/Server.hpp
- /__w/clio/clio/src/web/ng/Server.cpp