22#include "util/Taggable.hpp"
23#include "web/AdminVerificationStrategy.hpp"
24#include "web/ProxyIpResolver.hpp"
25#include "web/SslWsSession.hpp"
26#include "web/dosguard/DOSGuardInterface.hpp"
27#include "web/impl/HttpBase.hpp"
28#include "web/interface/Concepts.hpp"
29#include "web/interface/ConnectionBase.hpp"
31#include <boost/asio/ip/tcp.hpp>
32#include <boost/asio/ssl/context.hpp>
33#include <boost/asio/ssl/stream_base.hpp>
34#include <boost/beast/core/error.hpp>
35#include <boost/beast/core/flat_buffer.hpp>
36#include <boost/beast/core/stream_traits.hpp>
37#include <boost/beast/core/tcp_stream.hpp>
38#include <boost/beast/ssl/ssl_stream.hpp>
50using tcp = boost::asio::ip::tcp;
60template <SomeServerHandler HandlerType>
62 public std::enable_shared_from_this<SslHttpSession<HandlerType>> {
63 boost::beast::ssl_stream<boost::beast::tcp_stream> stream_;
64 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
65 std::uint32_t maxWsSendingQueueSize_;
84 std::string
const& ip,
85 std::shared_ptr<AdminVerificationStrategy>
const& adminVerification,
86 std::shared_ptr<ProxyIpResolver> proxyIpResolver,
87 boost::asio::ssl::context& ctx,
88 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
89 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
90 std::shared_ptr<HandlerType>
const& handler,
91 boost::beast::flat_buffer buffer,
92 std::uint32_t maxWsSendingQueueSize
98 std::move(proxyIpResolver),
103 , stream_(std::move(socket), ctx)
104 , tagFactory_(tagFactory)
105 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
112 boost::beast::ssl_stream<boost::beast::tcp_stream>&
122 auto self = this->shared_from_this();
123 boost::asio::dispatch(stream_.get_executor(), [self]() {
125 boost::beast::get_lowest_layer(self->stream()).expires_after(std::chrono::seconds(30));
129 self->stream_.async_handshake(
130 boost::asio::ssl::stream_base::server,
131 self->buffer_.data(),
132 boost::beast::bind_front_handler(&SslHttpSession<HandlerType>::onHandshake, self)
147 return this->httpFail(ec,
"handshake");
149 this->buffer_.consume(bytesUsed);
157 boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
170 return this->httpFail(ec,
"shutdown");
178 std::make_shared<SslWsUpgrader<HandlerType>>(
184 std::move(this->buffer_),
185 std::move(this->req_),
187 maxWsSendingQueueSize_
Represents a HTTPS connection established by a client.
Definition SslHttpSession.hpp:62
void upgrade()
Upgrades connection to secure websocket.
Definition SslHttpSession.hpp:176
void run()
Initiates the handshake.
Definition SslHttpSession.hpp:120
void onShutdown(boost::beast::error_code ec)
Handles a connection shutdown.
Definition SslHttpSession.hpp:167
void doClose()
Closes the underlying connection.
Definition SslHttpSession.hpp:155
SslHttpSession(tcp::socket &&socket, std::string const &ip, std::shared_ptr< AdminVerificationStrategy > const &adminVerification, std::shared_ptr< ProxyIpResolver > proxyIpResolver, 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:82
boost::beast::ssl_stream< boost::beast::tcp_stream > & stream()
Definition SslHttpSession.hpp:113
void onHandshake(boost::beast::error_code ec, std::size_t bytesUsed)
Handles the handshake.
Definition SslHttpSession.hpp:144
This is the implementation class for http sessions.
Definition HttpBase.hpp:83
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:118