22#include "util/Taggable.hpp"
23#include "util/log/Logger.hpp"
24#include "util/newconfig/ConfigDefinition.hpp"
25#include "web/ng/Connection.hpp"
26#include "web/ng/MessageHandler.hpp"
27#include "web/ng/ProcessingPolicy.hpp"
28#include "web/ng/Response.hpp"
29#include "web/ng/impl/ConnectionHandler.hpp"
31#include <boost/asio/io_context.hpp>
32#include <boost/asio/ip/tcp.hpp>
33#include <boost/asio/spawn.hpp>
34#include <boost/asio/ssl/context.hpp>
74 std::reference_wrapper<boost::asio::io_context> ctx_;
75 std::optional<boost::asio::ssl::context> sslContext_;
79 impl::ConnectionHandler connectionHandler_;
80 boost::asio::ip::tcp::endpoint endpoint_;
102 boost::asio::io_context& ctx,
103 boost::asio::ip::tcp::endpoint endpoint,
104 std::optional<boost::asio::ssl::context> sslContext,
105 ProcessingPolicy processingPolicy,
106 std::optional<size_t> parallelRequestLimit,
108 std::optional<size_t> maxSubscriptionSendQueueSize,
131 onGet(std::string
const& target, MessageHandler handler);
141 onPost(std::string
const& target, MessageHandler handler);
150 onWs(MessageHandler handler);
157 std::optional<std::string>
167 stop(boost::asio::yield_context yield);
171 handleConnection(boost::asio::ip::tcp::socket socket, boost::asio::yield_context yield);
184std::expected<Server, std::string>
189 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:169
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
A class representing a connection to a client.
Definition Connection.hpp:100
Web server class.
Definition Server.hpp:57
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:63
void onGet(std::string const &target, MessageHandler handler)
Set handler for GET requests.
Definition Server.cpp:214
std::optional< std::string > run()
Run the server.
Definition Server.cpp:235
Server(Server &&)=default
Move constructor is defaulted.
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.
Definition Server.cpp:193
void onPost(std::string const &target, MessageHandler handler)
Set handler for POST requests.
Definition Server.cpp:221
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:228
impl::ConnectionHandler::OnDisconnectHook OnDisconnectHook
Hook called when any connection disconnects.
Definition Server.hpp:68
A tag class for server to help identify Server in templated code.
Definition Server.hpp:47