3#include "util/Taggable.hpp"
4#include "util/config/ConfigDefinition.hpp"
5#include "util/log/Logger.hpp"
6#include "web/ProxyIpResolver.hpp"
7#include "web/interface/Concepts.hpp"
8#include "web/ng/Connection.hpp"
9#include "web/ng/MessageHandler.hpp"
10#include "web/ng/ProcessingPolicy.hpp"
11#include "web/ng/Response.hpp"
12#include "web/ng/impl/ConnectionHandler.hpp"
14#include <boost/asio/io_context.hpp>
15#include <boost/asio/ip/tcp.hpp>
16#include <boost/asio/spawn.hpp>
17#include <boost/asio/ssl/context.hpp>
63 std::reference_wrapper<boost::asio::io_context> ctx_;
64 std::optional<boost::asio::ssl::context> sslContext_;
67 size_t maxSubscriptionSendQueueSize_;
69 impl::ConnectionHandler connectionHandler_;
70 boost::asio::ip::tcp::endpoint endpoint_;
92 boost::asio::io_context& ctx,
93 boost::asio::ip::tcp::endpoint endpoint,
94 std::optional<boost::asio::ssl::context> sslContext,
96 std::optional<size_t> parallelRequestLimit,
98 ProxyIpResolver proxyIpResolver,
99 size_t maxSubscriptionSendQueueSize,
148 std::optional<std::string>
160 stop(boost::asio::yield_context yield);
164 handleConnection(boost::asio::ip::tcp::socket socket, boost::asio::yield_context yield);
178std::expected<Server, std::string>
184 boost::asio::io_context& context
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
A factory for TagDecorator instantiation.
Definition Taggable.hpp:165
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
A class representing a connection to a client.
Definition Connection.hpp:117
void stop(boost::asio::yield_context yield)
Stop the server. This method will asynchronously sleep unless all the users are disconnected.
Definition Server.cpp:278
std::function< std::expected< void, Response >(Connection const &)> OnConnectCheck
Check to perform for each new client connection. The check takes client ip as input and returns a Res...
Definition Server.hpp:36
void onGet(std::string const &target, MessageHandler handler)
Set handler for GET requests.
Definition Server.cpp:220
std::optional< std::string > run()
Run the server.
Definition Server.cpp:241
impl::ConnectionHandler::OnIpChangeHook OnIpChangeHook
Hook called when a connection's client ip changes (e.g. resolved from a proxy).
Definition Server.hpp:43
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, ProxyIpResolver proxyIpResolver, size_t maxSubscriptionSendQueueSize, Hooks hooks)
Construct a new Server object.
Definition Server.cpp:198
void onPost(std::string const &target, MessageHandler handler)
Set handler for POST requests.
Definition Server.cpp:227
Server(Server const &)=delete
Copy constructor is deleted. The Server couldn't be copied.
void onWs(MessageHandler handler)
Set handler for WebSocket requests.
Definition Server.cpp:234
Server(Server &&)=delete
Move constructor is deleted because connectionHandler_ contains references to some fields of the Serv...
impl::ConnectionHandler::OnDisconnectHook OnDisconnectHook
Hook called when any connection disconnects.
Definition Server.hpp:48
The next generation web server implementation.
Definition Connection.cpp:10
std::expected< Server, std::string > makeServer(util::config::ClioConfigDefinition const &config, Server::OnConnectCheck onConnectCheck, Server::OnIpChangeHook onIpChangeHook, Server::OnDisconnectHook onDisconnectHook, boost::asio::io_context &context)
Create a new Server.
Definition Server.cpp:351
std::function< Response( Request const &, ConnectionMetadata &, SubscriptionContextPtr, boost::asio::yield_context)> MessageHandler
Handler for messages.
Definition MessageHandler.hpp:17
ProcessingPolicy
Requests processing policy.
Definition ProcessingPolicy.hpp:8
A tag class for server to help identify Server in templated code.
Definition Concepts.hpp:33
A struct that holds all the hooks for the server.
Definition Server.hpp:53
OnConnectCheck onConnectCheck
Check performed for each new client connection.
Definition Server.hpp:54
OnDisconnectHook onDisconnectHook
Hook called when a connection disconnects.
Definition Server.hpp:56
OnIpChangeHook onIpChangeHook
Hook called when a connection's client ip changes.
Definition Server.hpp:55