22#include "util/Taggable.hpp"
23#include "web/dosguard/DOSGuardInterface.hpp"
24#include "web/impl/WsBase.hpp"
25#include "web/interface/ConnectionBase.hpp"
27#include <boost/beast/core/flat_buffer.hpp>
28#include <boost/beast/core/stream_traits.hpp>
29#include <boost/beast/core/tcp_stream.hpp>
30#include <boost/beast/http/message.hpp>
31#include <boost/beast/http/parser.hpp>
32#include <boost/beast/http/string_body.hpp>
33#include <boost/beast/ssl.hpp>
34#include <boost/beast/ssl/ssl_stream.hpp>
35#include <boost/beast/websocket/stream.hpp>
36#include <boost/optional/optional.hpp>
52template <SomeServerHandler HandlerType>
54 using StreamType = boost::beast::websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>>;
71 boost::beast::ssl_stream<boost::beast::tcp_stream>&& stream,
73 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
74 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
75 std::shared_ptr<HandlerType>
const& handler,
76 boost::beast::flat_buffer&& buffer,
78 std::uint32_t maxWsSendingQueueSize
88 , ws_(std::move(stream))
90 ConnectionBase::isAdmin_ =
isAdmin;
106template <SomeServerHandler HandlerType>
107class SslWsUpgrader :
public std::enable_shared_from_this<SslWsUpgrader<HandlerType>> {
110 boost::beast::ssl_stream<boost::beast::tcp_stream> https_;
111 boost::optional<http::request_parser<http::string_body>> parser_;
112 boost::beast::flat_buffer buffer_;
114 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
115 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard_;
116 std::shared_ptr<HandlerType>
const handler_;
117 http::request<http::string_body> req_;
119 std::uint32_t maxWsSendingQueueSize_;
136 boost::beast::ssl_stream<boost::beast::tcp_stream> stream,
138 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
139 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
140 std::shared_ptr<HandlerType> handler,
141 boost::beast::flat_buffer&& buffer,
142 http::request<http::string_body> request,
144 std::uint32_t maxWsSendingQueueSize
146 : https_(std::move(stream))
147 , buffer_(std::move(buffer))
149 , tagFactory_(tagFactory)
150 , dosGuard_(dosGuard)
151 , handler_(std::move(handler))
152 , req_(std::move(request))
154 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
164 boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
166 boost::asio::dispatch(
167 https_.get_executor(),
179 static constexpr auto kMAX_BODY_SIZE = 10000;
180 parser_->body_limit(kMAX_BODY_SIZE);
182 boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
189 if (!boost::beast::websocket::is_upgrade(req_))
193 boost::beast::get_lowest_layer(https_).expires_never();
195 std::make_shared<SslWsSession<HandlerType>>(
203 maxWsSendingQueueSize_
205 ->
run(std::move(req_));
Represents a secure websocket session.
Definition SslWsSession.hpp:53
SslWsSession(boost::beast::ssl_stream< boost::beast::tcp_stream > &&stream, std::string ip, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > const &handler, boost::beast::flat_buffer &&buffer, bool isAdmin, std::uint32_t maxWsSendingQueueSize)
Create a new non-secure websocket session.
Definition SslWsSession.hpp:70
StreamType & ws()
Definition SslWsSession.hpp:95
The HTTPS upgrader class, upgrade from an HTTPS session to a secure websocket session.
Definition SslWsSession.hpp:107
void run()
Initiate the upgrade.
Definition SslWsSession.hpp:162
SslWsUpgrader(boost::beast::ssl_stream< boost::beast::tcp_stream > stream, std::string ip, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > handler, boost::beast::flat_buffer &&buffer, http::request< http::string_body > request, bool isAdmin, std::uint32_t maxWsSendingQueueSize)
Create a new upgrader to secure websocket.
Definition SslWsSession.hpp:135
Web socket implementation. This class is the base class of the web socket session,...
Definition WsBase.hpp:75
This namespace implements the web server and related components.
Definition Types.hpp:43
bool isAdmin() const
Indicates whether the connection has admin privileges.
Definition ConnectionBase.hpp:111