Kagome
Polkadot Runtime Engine in C++17
kagome::api::HttpSession Class Reference

HTTP session for api service. More...

#include <http_session.hpp>

Inheritance diagram for kagome::api::HttpSession:
Collaboration diagram for kagome::api::HttpSession:

Classes

struct  Configuration
 

Public Member Functions

 ~HttpSession () override=default
 
 HttpSession (Context &context, Configuration config)
 constructor More...
 
Socketsocket () override
 
void start () override
 starts session More...
 
void respond (std::string_view response) override
 sends response wrapped by http message More...
 
SessionId id () const override
 method to get id of the session More...
 
SessionType type () const override
 method to get type of the session More...
 
template<class Body >
void handleRequest (boost::beast::http::request< Body > &&req)
 
- Public Member Functions inherited from kagome::api::Session
virtual ~Session ()=default
 
void connectOnRequest (std::function< OnRequestSignature > callback)
 connects on request callback More...
 
void connectOnCloseHandler (OnCloseHandler &&handler)
 connects on close callback More...
 
void processRequest (std::string_view request, std::shared_ptr< Session > session)
 process request message More...
 
void notifyOnClose (SessionId id, SessionType type)
 makes on close notification to listener More...
 

Private Types

template<typename Body >
using Request = boost::beast::http::request< Body >
 
template<typename Body >
using Response = boost::beast::http::response< Body >
 
using StringBody = boost::beast::http::string_body
 
template<class Body >
using RequestParser = boost::beast::http::request_parser< Body >
 
using HttpField = boost::beast::http::field
 
using HttpError = boost::beast::http::error
 
using Parser = RequestParser< StringBody >
 request parser type More...
 

Private Member Functions

void stop ()
 stops session More...
 
template<class Body >
void handleRequest (Request< Body > &&request)
 process http request, compose and execute response More...
 
void asyncRead ()
 asynchronously read http message More...
 
template<class Message >
void asyncWrite (Message &&message)
 sends http message More...
 
void onRead (boost::system::error_code ec, std::size_t size)
 read completion callback More...
 
void onWrite (boost::system::error_code ec, std::size_t, bool close)
 write completion callback More...
 
auto makeBadResponse (std::string_view message, unsigned version, bool keep_alive)
 composes bad request message More...
 
void reportError (boost::system::error_code ec, std::string_view message)
 reports error code and message More...
 

Private Attributes

boost::asio::strand< boost::asio::io_context::executor_type > strand_
 Strand to ensure the connection's handlers are not called concurrently. More...
 
Configuration config_
 session configuration More...
 
boost::beast::tcp_stream stream_
 stream More...
 
boost::beast::flat_buffer buffer_
 read buffer More...
 
std::unique_ptr< Parserparser_
 http parser More...
 
log::Logger logger_ = log::createLogger("HttpSession", "rpc_transport")
 

Static Private Attributes

static constexpr boost::string_view kServerName = "Kagome"
 

Additional Inherited Members

- Public Types inherited from kagome::api::Session
using Context = RpcContext
 
using Socket = boost::asio::ip::tcp::socket
 
using ErrorCode = boost::system::error_code
 
using Streambuf = boost::asio::streambuf
 
using Timer = boost::asio::steady_timer
 
using Connection = boost::signals2::connection
 
using Duration = Timer::duration
 
using SessionId = uint64_t
 
using OnCloseHandler = std::function< void(SessionId, SessionType)>
 Event handlers. More...
 

Detailed Description

HTTP session for api service.

Definition at line 22 of file http_session.hpp.

Member Typedef Documentation

using kagome::api::HttpSession::HttpError = boost::beast::http::error
private

Definition at line 37 of file http_session.hpp.

using kagome::api::HttpSession::HttpField = boost::beast::http::field
private

Definition at line 35 of file http_session.hpp.

request parser type

Definition at line 156 of file http_session.hpp.

template<typename Body >
using kagome::api::HttpSession::Request = boost::beast::http::request<Body>
private

Definition at line 25 of file http_session.hpp.

template<class Body >
using kagome::api::HttpSession::RequestParser = boost::beast::http::request_parser<Body>
private

Definition at line 33 of file http_session.hpp.

template<typename Body >
using kagome::api::HttpSession::Response = boost::beast::http::response<Body>
private

Definition at line 28 of file http_session.hpp.

using kagome::api::HttpSession::StringBody = boost::beast::http::string_body
private

Definition at line 30 of file http_session.hpp.

Constructor & Destructor Documentation

kagome::api::HttpSession::~HttpSession ( )
overridedefault
kagome::api::HttpSession::HttpSession ( Context context,
Configuration  config 
)

constructor

Parameters
socketsocket instance
configsession configuration

Definition at line 14 of file http_session.cpp.

Member Function Documentation

void kagome::api::HttpSession::asyncRead ( )
private

asynchronously read http message

Definition at line 52 of file http_session.cpp.

template<class Message >
void kagome::api::HttpSession::asyncWrite ( Message &&  message)
private

sends http message

Template Parameters
Messagehttp message type
Parameters
messagehttp message

Definition at line 69 of file http_session.cpp.

template<class Body >
void kagome::api::HttpSession::handleRequest ( boost::beast::http::request< Body > &&  req)

Definition at line 42 of file http_session.cpp.

template<class Body >
void kagome::api::HttpSession::handleRequest ( Request< Body > &&  request)
private

process http request, compose and execute response

Template Parameters
Bodyrequest body type
Parameters
requestrequest
SessionId kagome::api::HttpSession::id ( ) const
inlineoverridevirtual

method to get id of the session

Returns
id of the session

Implements kagome::api::Session.

Definition at line 76 of file http_session.hpp.

auto kagome::api::HttpSession::makeBadResponse ( std::string_view  message,
unsigned  version,
bool  keep_alive 
)
private

composes bad request message

Parameters
messagetext to send
versionprotocol version
keep_alivetrue if server should keep connection alive, false otherwise
Returns
composed request

Definition at line 29 of file http_session.cpp.

void kagome::api::HttpSession::onRead ( boost::system::error_code  ec,
std::size_t  size 
)
private

read completion callback

Definition at line 99 of file http_session.cpp.

void kagome::api::HttpSession::onWrite ( boost::system::error_code  ec,
std::size_t  ,
bool  close 
)
private

write completion callback

Definition at line 112 of file http_session.cpp.

void kagome::api::HttpSession::reportError ( boost::system::error_code  ec,
std::string_view  message 
)
private

reports error code and message

Parameters
ecerror code
messageerror message

Definition at line 128 of file http_session.cpp.

void kagome::api::HttpSession::respond ( std::string_view  response)
overridevirtual

sends response wrapped by http message

Parameters
responsemessage to send

Implements kagome::api::Session.

Definition at line 82 of file http_session.cpp.

Socket& kagome::api::HttpSession::socket ( )
inlineoverridevirtual

Implements kagome::api::Session.

Definition at line 57 of file http_session.hpp.

void kagome::api::HttpSession::start ( )
overridevirtual

starts session

Implements kagome::api::Session.

Definition at line 19 of file http_session.cpp.

void kagome::api::HttpSession::stop ( )
private

stops session

Definition at line 23 of file http_session.cpp.

SessionType kagome::api::HttpSession::type ( ) const
inlineoverridevirtual

method to get type of the session

Returns
type of the session

Implements kagome::api::Session.

Definition at line 84 of file http_session.hpp.

Member Data Documentation

boost::beast::flat_buffer kagome::api::HttpSession::buffer_
private

read buffer

Definition at line 151 of file http_session.hpp.

Configuration kagome::api::HttpSession::config_
private

session configuration

Definition at line 149 of file http_session.hpp.

constexpr boost::string_view kagome::api::HttpSession::kServerName = "Kagome"
staticprivate

Definition at line 144 of file http_session.hpp.

log::Logger kagome::api::HttpSession::logger_ = log::createLogger("HttpSession", "rpc_transport")
private

Definition at line 159 of file http_session.hpp.

std::unique_ptr<Parser> kagome::api::HttpSession::parser_
private

http parser

Definition at line 158 of file http_session.hpp.

boost::asio::strand<boost::asio::io_context::executor_type> kagome::api::HttpSession::strand_
private

Strand to ensure the connection's handlers are not called concurrently.

Definition at line 147 of file http_session.hpp.

boost::beast::tcp_stream kagome::api::HttpSession::stream_
private

stream

Definition at line 150 of file http_session.hpp.


The documentation for this class was generated from the following files: