22#include "util/Taggable.hpp"
23#include "util/config/ConfigDefinition.hpp"
24#include "util/log/Logger.hpp"
25#include "web/ProxyIpResolver.hpp"
26#include "web/ng/Connection.hpp"
27#include "web/ng/MessageHandler.hpp"
28#include "web/ng/ProcessingPolicy.hpp"
29#include "web/ng/Response.hpp"
30#include "web/ng/impl/ConnectionHandler.hpp"
32#include <boost/asio/io_context.hpp>
33#include <boost/asio/ip/tcp.hpp>
34#include <boost/asio/spawn.hpp>
35#include <boost/asio/ssl/context.hpp>
66 using OnIpChangeHook = impl::ConnectionHandler::OnIpChangeHook;
78 OnIpChangeHook onIpChangeHook;
86 std::reference_wrapper<boost::asio::io_context> ctx_;
87 std::optional<boost::asio::ssl::context> sslContext_;
91 impl::ConnectionHandler connectionHandler_;
92 boost::asio::ip::tcp::endpoint endpoint_;
114 boost::asio::io_context& ctx,
115 boost::asio::ip::tcp::endpoint endpoint,
116 std::optional<boost::asio::ssl::context> sslContext,
117 ProcessingPolicy processingPolicy,
118 std::optional<size_t> parallelRequestLimit,
120 ProxyIpResolver proxyIpResolver,
121 std::optional<size_t> maxSubscriptionSendQueueSize,
143 onGet(std::string
const& target, MessageHandler handler);
153 onPost(std::string
const& target, MessageHandler handler);
162 onWs(MessageHandler handler);
169 std::optional<std::string>
179 stop(boost::asio::yield_context yield);
183 handleConnection(boost::asio::ip::tcp::socket socket, boost::asio::yield_context yield);
196std::expected<Server, std::string>
200 Server::OnIpChangeHook onIpChangeHook,
202 boost::asio::io_context& context
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:87
A factory for TagDecorator instantiation.
Definition Taggable.hpp:182
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
A class representing a connection to a client.
Definition Connection.hpp:112
Web server class.
Definition Server.hpp:58
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:64
void onGet(std::string const &target, MessageHandler handler)
Set handler for GET requests.
Definition Server.cpp:223
std::optional< std::string > run()
Run the server.
Definition Server.cpp:244
void onPost(std::string const &target, MessageHandler handler)
Set handler for POST requests.
Definition Server.cpp:230
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, std::optional< size_t > maxSubscriptionSendQueueSize, Hooks hooks)
Construct a new Server object.
Definition Server.cpp:202
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:237
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:71
A tag class for server to help identify Server in templated code.
Definition Server.hpp:48
A struct that holds all the hooks for the server.
Definition Server.hpp:76