22#include "util/Taggable.hpp"
23#include "web/AdminVerificationStrategy.hpp"
24#include "web/SslWsSession.hpp"
25#include "web/dosguard/DOSGuardInterface.hpp"
26#include "web/impl/HttpBase.hpp"
27#include "web/interface/Concepts.hpp"
28#include "web/interface/ConnectionBase.hpp"
30#include <boost/asio/ip/tcp.hpp>
31#include <boost/asio/ssl/context.hpp>
32#include <boost/asio/ssl/stream_base.hpp>
33#include <boost/beast/core/error.hpp>
34#include <boost/beast/core/flat_buffer.hpp>
35#include <boost/beast/core/stream_traits.hpp>
36#include <boost/beast/core/tcp_stream.hpp>
37#include <boost/beast/ssl/ssl_stream.hpp>
49using tcp = boost::asio::ip::tcp;
59template <SomeServerHandler HandlerType>
61 public std::enable_shared_from_this<SslHttpSession<HandlerType>> {
62 boost::beast::ssl_stream<boost::beast::tcp_stream> stream_;
63 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
64 std::uint32_t maxWsSendingQueueSize_;
82 std::string
const& ip,
83 std::shared_ptr<AdminVerificationStrategy>
const& adminVerification,
84 boost::asio::ssl::context& ctx,
85 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
86 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
87 std::shared_ptr<HandlerType>
const& handler,
88 boost::beast::flat_buffer buffer,
89 std::uint32_t maxWsSendingQueueSize
99 , stream_(std::move(socket), ctx)
100 , tagFactory_(tagFactory)
101 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
108 boost::beast::ssl_stream<boost::beast::tcp_stream>&
118 auto self = this->shared_from_this();
119 boost::asio::dispatch(stream_.get_executor(), [self]() {
121 boost::beast::get_lowest_layer(self->stream()).expires_after(std::chrono::seconds(30));
125 self->stream_.async_handshake(
126 boost::asio::ssl::stream_base::server,
127 self->buffer_.data(),
128 boost::beast::bind_front_handler(&SslHttpSession<HandlerType>::onHandshake, self)
143 return this->httpFail(ec,
"handshake");
145 this->buffer_.consume(bytesUsed);
153 boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
166 return this->httpFail(ec,
"shutdown");
174 std::make_shared<SslWsUpgrader<HandlerType>>(
180 std::move(this->buffer_),
181 std::move(this->req_),
183 maxWsSendingQueueSize_
Represents a HTTPS connection established by a client.
Definition SslHttpSession.hpp:61
void upgrade()
Upgrades connection to secure websocket.
Definition SslHttpSession.hpp:172
void run()
Initiates the handshake.
Definition SslHttpSession.hpp:116
void onShutdown(boost::beast::error_code ec)
Handles a connection shutdown.
Definition SslHttpSession.hpp:163
void doClose()
Closes the underlying connection.
Definition SslHttpSession.hpp:151
SslHttpSession(tcp::socket &&socket, std::string const &ip, std::shared_ptr< AdminVerificationStrategy > const &adminVerification, boost::asio::ssl::context &ctx, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > const &handler, boost::beast::flat_buffer buffer, std::uint32_t maxWsSendingQueueSize)
Create a new SSL session.
Definition SslHttpSession.hpp:80
boost::beast::ssl_stream< boost::beast::tcp_stream > & stream()
Definition SslHttpSession.hpp:109
void onHandshake(boost::beast::error_code ec, std::size_t bytesUsed)
Handles the handshake.
Definition SslHttpSession.hpp:140
This is the implementation class for http sessions.
Definition HttpBase.hpp:82
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