3#include "util/Taggable.hpp"
4#include "web/dosguard/DOSGuardInterface.hpp"
5#include "web/impl/WsBase.hpp"
6#include "web/interface/ConnectionBase.hpp"
8#include <boost/beast/core/flat_buffer.hpp>
9#include <boost/beast/core/stream_traits.hpp>
10#include <boost/beast/core/tcp_stream.hpp>
11#include <boost/beast/http/message.hpp>
12#include <boost/beast/http/parser.hpp>
13#include <boost/beast/http/string_body.hpp>
14#include <boost/beast/ssl.hpp>
15#include <boost/beast/ssl/ssl_stream.hpp>
16#include <boost/beast/websocket/stream.hpp>
17#include <boost/optional/optional.hpp>
33template <SomeServerHandler HandlerType>
36 boost::beast::websocket::stream<boost::asio::ssl::stream<boost::beast::tcp_stream>>;
53 boost::asio::ssl::stream<boost::beast::tcp_stream>&& stream,
55 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
56 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
57 std::shared_ptr<HandlerType>
const& handler,
58 boost::beast::flat_buffer&& buffer,
60 std::uint32_t maxWsSendingQueueSize
70 , ws_(std::move(stream))
72 ConnectionBase::isAdmin_ =
isAdmin;
88template <SomeServerHandler HandlerType>
89class SslWsUpgrader :
public std::enable_shared_from_this<SslWsUpgrader<HandlerType>> {
92 boost::asio::ssl::stream<boost::beast::tcp_stream> https_;
93 boost::optional<http::request_parser<http::string_body>> parser_;
94 boost::beast::flat_buffer buffer_;
96 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
97 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard_;
98 std::shared_ptr<HandlerType>
const handler_;
99 http::request<http::string_body> req_;
101 std::uint32_t maxWsSendingQueueSize_;
118 boost::asio::ssl::stream<boost::beast::tcp_stream> stream,
120 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
121 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
122 std::shared_ptr<HandlerType> handler,
123 boost::beast::flat_buffer&& buffer,
124 http::request<http::string_body> request,
126 std::uint32_t maxWsSendingQueueSize
128 : https_(std::move(stream))
129 , buffer_(std::move(buffer))
131 , tagFactory_(tagFactory)
132 , dosGuard_(dosGuard)
133 , handler_(std::move(handler))
134 , req_(std::move(request))
136 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
146 boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
148 boost::asio::dispatch(
149 https_.get_executor(),
150 boost::beast::bind_front_handler(
151 &SslWsUpgrader<HandlerType>::doUpgrade, shared_from_this()
163 static constexpr auto kMAX_BODY_SIZE = 10000;
164 parser_->body_limit(kMAX_BODY_SIZE);
166 boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
173 if (!boost::beast::websocket::is_upgrade(req_))
177 boost::beast::get_lowest_layer(https_).expires_never();
179 std::make_shared<SslWsSession<HandlerType>>(
187 maxWsSendingQueueSize_
189 ->
run(std::move(req_));
SslWsSession(boost::asio::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:52
StreamType & ws()
Definition SslWsSession.hpp:77
The HTTPS upgrader class, upgrade from an HTTPS session to a secure websocket session.
Definition SslWsSession.hpp:89
void run()
Initiate the upgrade.
Definition SslWsSession.hpp:144
SslWsUpgrader(boost::asio::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:117
Web socket implementation. This class is the base class of the web socket session,...
Definition WsBase.hpp:57
This namespace implements the web server and related components.
Definition Types.hpp:24
bool isAdmin() const
Indicates whether the connection has admin privileges.
Definition ConnectionBase.hpp:99