roar
|
#include <session.hpp>
Classes | |
struct | Implementation |
class | ReadIntermediate |
Utility class to build up read operations. More... | |
class | SendIntermediate |
Helper class to prepare and send a response. More... | |
Public Member Functions | |
Session (boost::asio::basic_stream_socket< boost::asio::ip::tcp > &&socket, boost::beast::basic_flat_buffer< std::allocator< char > > &&buffer, std::optional< std::variant< SslServerContext, boost::asio::ssl::context > > &sslContext, bool isSecure, std::function< void(Error &&)> onError, std::weak_ptr< Router > router, std::shared_ptr< const StandardResponseProvider > standardResponseProvider) | |
ROAR_PIMPL_SPECIAL_FUNCTIONS (Session) | |
void | close () |
Calls shutdown on the socket. | |
template<typename BodyT , typename OriginalBodyT , typename... Forwards> | |
std::shared_ptr< SendIntermediate< BodyT > > | send (Request< OriginalBodyT > const &req, Forwards &&... forwards) |
template<typename BodyT > | |
std::shared_ptr< SendIntermediate< BodyT > > | send (boost::beast::http::response< BodyT > &&res) |
template<typename BodyT > | |
std::shared_ptr< SendIntermediate< BodyT > > | send (Response< BodyT > &&res) |
template<typename BodyT > | |
std::shared_ptr< SendIntermediate< BodyT > > | sendWithAllAcceptedCors () |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::size_t >, Detail::PromiseTypeBindFail< Error > > | send (std::string message, std::chrono::seconds timeout=std::chrono::seconds{10}) |
Send raw data. Use this after sending a proper response for sending additional data. | |
void | readLimit (std::size_t bytesPerSecond) |
Sets a rate limit in bytes/second for this session for reading. | |
void | writeLimit (std::size_t bytesPerSecond) |
Sets a rate limit in bytes/second for this session for writing. | |
template<typename BodyT , typename OriginalBodyT , typename... Forwards> | |
std::shared_ptr< ReadIntermediate< BodyT > > | read (Request< OriginalBodyT > req, Forwards &&... forwardArgs) |
Read data from the client. | |
template<typename BodyT = boost::beast::http::empty_body, typename RequestBodyT , typename... Forwards> | |
Response< BodyT > | prepareResponse (Request< RequestBodyT > const &req, Forwards &&... forwardArgs) |
Prepares a response with some header values already set. | |
template<typename BodyT = boost::beast::http::empty_body> | |
Response< BodyT > | prepareResponse () |
template<typename FunctionT > | |
void | withStreamDo (FunctionT &&func) |
std::visit for the underlying beast stream. Either ssl_stream or tcp_stream. | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::shared_ptr< WebsocketSession > >, Detail::PromiseTypeBindFail< Error const & > > | upgrade (Request< boost::beast::http::empty_body > const &req) |
Turn this session into a websocket session. Will return an invalid shared_ptr if this is not an upgrade request. | |
RouteOptions const & | routeOptions () |
Retrieve the options defined by the request listener class for this route. | |
bool | isSecure () const |
Returns whether or not this is an encrypted session. | |
void | sendStandardResponse (boost::beast::http::status status, std::string_view additionalInfo="") |
Sends a standard response like "404 not found". | |
void | sendStrictTransportSecurityResponse () |
Sends a 403 with Strict-Transport-Security. Used only for unencrypted request on enforced HTTPS. | |
template<typename OriginalBodyT > | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error const & > > | awaitClientClose (Request< OriginalBodyT > req, std::chrono::milliseconds timeout=std::chrono::seconds{3}) |
Some clients insist on closing the connection on their own even if they received a response. To avoid this, this function can be called and the connection will be kept alive until the client closes it or a timeout is reached. | |
Static Public Attributes | |
static constexpr uint64_t | defaultHeaderLimit {8_MiB} |
static constexpr uint64_t | defaultBodyLimit {8_MiB} |
static constexpr std::chrono::seconds | sessionTimeout {10} |
Private Member Functions | |
void | setupRouteOptions (RouteOptions options) |
void | readHeader () |
void | performSslHandshake () |
bool | onWriteComplete (bool expectsClose, boost::beast::error_code ec, std::size_t) |
std::variant< Detail::StreamType, boost::beast::ssl_stream< Detail::StreamType > > & | stream () |
std::shared_ptr< boost::beast::http::request_parser< boost::beast::http::empty_body > > & | parser () |
boost::beast::flat_buffer & | buffer () |
StandardResponseProvider const & | standardResponseProvider () |
void | startup (bool immediate=true) |
Private Attributes | |
std::unique_ptr< Implementation > | impl_ |
Friends | |
class | Route |
class | Factory |
Roar::Session::Session | ( | boost::asio::basic_stream_socket< boost::asio::ip::tcp > && | socket, |
boost::beast::basic_flat_buffer< std::allocator< char > > && | buffer, | ||
std::optional< std::variant< SslServerContext, boost::asio::ssl::context > > & | sslContext, | ||
bool | isSecure, | ||
std::function< void(Error &&)> | onError, | ||
std::weak_ptr< Router > | router, | ||
std::shared_ptr< const StandardResponseProvider > | standardResponseProvider | ||
) |
|
inline |
Some clients insist on closing the connection on their own even if they received a response. To avoid this, this function can be called and the connection will be kept alive until the client closes it or a timeout is reached.
|
private |
void Roar::Session::close | ( | ) |
Calls shutdown on the socket.
bool Roar::Session::isSecure | ( | ) | const |
|
private |
|
private |
|
private |
|
inline |
|
inline |
Prepares a response with some header values already set.
BodyT |
|
inline |
Read data from the client.
BodyT | What body type to read? |
OriginalBodyT | Body of the request that came before the this read. |
Forwards |
req | A request that was received |
forwardArgs |
|
private |
void Roar::Session::readLimit | ( | std::size_t | bytesPerSecond | ) |
Sets a rate limit in bytes/second for this session for reading.
bytesPerSecond |
Roar::Session::ROAR_PIMPL_SPECIAL_FUNCTIONS | ( | Session | ) |
RouteOptions const & Roar::Session::routeOptions | ( | ) |
Retrieve the options defined by the request listener class for this route.
|
inline |
|
inline |
|
inline |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::size_t >, Detail::PromiseTypeBindFail< Error > > Roar::Session::send | ( | std::string | message, |
std::chrono::seconds | timeout = std::chrono::seconds{10} |
||
) |
Send raw data. Use this after sending a proper response for sending additional data.
data |
void Roar::Session::sendStandardResponse | ( | boost::beast::http::status | status, |
std::string_view | additionalInfo = "" |
||
) |
Sends a standard response like "404 not found".
status | The status to send. |
additionalInfo | Some additional info added into the body (depends on standardResponseProvider). |
void Roar::Session::sendStrictTransportSecurityResponse | ( | ) |
Sends a 403 with Strict-Transport-Security. Used only for unencrypted request on enforced HTTPS.
|
inline |
|
private |
|
private |
|
private |
|
private |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::shared_ptr< WebsocketSession > >, Detail::PromiseTypeBindFail< Error const & > > Roar::Session::upgrade | ( | Request< boost::beast::http::empty_body > const & | req | ) |
Turn this session into a websocket session. Will return an invalid shared_ptr if this is not an upgrade request.
req | The request to perform this upgrade from. |
|
inline |
std::visit for the underlying beast stream. Either ssl_stream or tcp_stream.
FunctionT |
func |
void Roar::Session::writeLimit | ( | std::size_t | bytesPerSecond | ) |
Sets a rate limit in bytes/second for this session for writing.
bytesPerSecond |
|
friend |
|
friend |
|
staticconstexpr |
|
staticconstexpr |
|
private |
|
staticconstexpr |