6 #ifndef KAGOME_CORE_API_TRANSPORT_BEAST_HTTP_SESSION_HPP 7 #define KAGOME_CORE_API_TRANSPORT_BEAST_HTTP_SESSION_HPP 9 #include <boost/asio/strand.hpp> 10 #include <boost/beast.hpp> 23 public std::enable_shared_from_this<HttpSession> {
24 template <
typename Body>
25 using Request = boost::beast::http::request<Body>;
27 template <
typename Body>
28 using Response = boost::beast::http::response<Body>;
64 void start()
override;
70 void respond(std::string_view response)
override;
112 template <
class Message>
118 void onRead(boost::system::error_code ec, std::size_t size);
123 void onWrite(boost::system::error_code ec, std::size_t,
bool close);
142 void reportError(boost::system::error_code ec, std::string_view message);
147 boost::asio::strand<boost::asio::io_context::executor_type>
strand_;
164 #endif // KAGOME_CORE_API_TRANSPORT_BEAST_HTTP_SESSION_HPP void onRead(boost::system::error_code ec, std::size_t size)
read completion callback
static constexpr Duration kDefaultTimeout
boost::beast::http::string_body StringBody
Duration operation_timeout
boost::beast::http::field HttpField
Configuration config_
session configuration
boost::beast::http::error HttpError
static constexpr boost::string_view kServerName
void reportError(boost::system::error_code ec, std::string_view message)
reports error code and message
boost::asio::ip::tcp::socket Socket
boost::asio::strand< boost::asio::io_context::executor_type > strand_
Strand to ensure the connection's handlers are not called concurrently.
SessionType type() const override
method to get type of the session
auto makeBadResponse(std::string_view message, unsigned version, bool keep_alive)
composes bad request message
void handleRequest(Request< Body > &&request)
process http request, compose and execute response
Socket & socket() override
boost::beast::http::response< Body > Response
void onWrite(boost::system::error_code ec, std::size_t, bool close)
write completion callback
boost::beast::http::request< Body > Request
boost::beast::tcp_stream stream_
stream
std::shared_ptr< soralog::Logger > Logger
void start() override
starts session
HTTP session for api service.
boost::beast::flat_buffer buffer_
read buffer
SessionId id() const override
method to get id of the session
HttpSession(Context &context, Configuration config)
constructor
void asyncRead()
asynchronously read http message
boost::beast::http::request_parser< Body > RequestParser
Logger createLogger(const std::string &tag)
void asyncWrite(Message &&message)
sends http message
RequestParser< StringBody > Parser
request parser type
std::unique_ptr< Parser > parser_
http parser
static constexpr size_t kDefaultRequestSize
void respond(std::string_view response) override
sends response wrapped by http message
~HttpSession() override=default