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>
38 using OnIpChangeHook = impl::ConnectionHandler::OnIpChangeHook;
50 OnIpChangeHook onIpChangeHook;
58 std::reference_wrapper<boost::asio::io_context> ctx_;
59 std::optional<boost::asio::ssl::context> sslContext_;
63 impl::ConnectionHandler connectionHandler_;
64 boost::asio::ip::tcp::endpoint endpoint_;
86 boost::asio::io_context& ctx,
87 boost::asio::ip::tcp::endpoint endpoint,
88 std::optional<boost::asio::ssl::context> sslContext,
89 ProcessingPolicy processingPolicy,
90 std::optional<size_t> parallelRequestLimit,
92 ProxyIpResolver proxyIpResolver,
93 std::optional<size_t> maxSubscriptionSendQueueSize,
116 onGet(std::string
const& target, MessageHandler handler);
126 onPost(std::string
const& target, MessageHandler handler);
135 onWs(MessageHandler handler);
142 std::optional<std::string>
154 stop(boost::asio::yield_context yield);
158 handleConnection(boost::asio::ip::tcp::socket socket, boost::asio::yield_context yield);
171std::expected<Server, std::string>
175 Server::OnIpChangeHook onIpChangeHook,
177 boost::asio::io_context& context
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
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:93
void stop(boost::asio::yield_context yield)
Stop the server. This method will asynchronously sleep unless all the users are disconnected.
Definition Server.cpp:270
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:212
std::optional< std::string > run()
Run the server.
Definition Server.cpp:233
void onPost(std::string const &target, MessageHandler handler)
Set handler for POST requests.
Definition Server.cpp:219
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:191
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:226
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:43
A tag class for server to help identify Server in templated code.
Definition Concepts.hpp:31
A struct that holds all the hooks for the server.
Definition Server.hpp:48