3#include <xrpl/beast/rfc2616.h>
4#include <xrpl/server/detail/BaseHTTPPeer.h>
5#include <xrpl/server/detail/PlainWSPeer.h>
7#include <boost/beast/core/tcp_stream.hpp>
13template <
class Handler>
27 template <
class ConstBufferSequence>
31 boost::asio::io_context& ioc,
34 ConstBufferSequence
const& buffers,
53template <
class Handler>
54template <
class ConstBufferSequence>
58 boost::asio::io_context& ioc,
61 ConstBufferSequence
const& buffers,
64 , stream_(
std::move(stream))
65 , socket_(stream_.socket())
71 if (remote_endpoint.address().is_loopback())
72 socket_.set_option(boost::asio::ip::tcp::no_delay{
true});
75template <
class Handler>
79 if (!this->handler_.onAccept(this->session(), this->remote_address_))
85 if (!socket_.is_open())
91template <
class Handler>
95 auto ws = this->ios().template emplace<PlainWSPeer<Handler>>(
98 this->remote_address_,
99 std::move(this->message_),
105template <
class Handler>
109 ++this->request_count_;
110 auto const what = this->handler_.onHandoff(this->session(), std::move(this->message_), this->remote_address_);
113 boost::system::error_code ec;
117 if (!what.keep_alive)
118 socket_.shutdown(socket_type::shutdown_receive, ec);
120 return this->fail(ec,
"request");
121 return this->write(what.response, what.keep_alive);
126 socket_.shutdown(socket_type::shutdown_receive, ec);
128 return this->fail(ec,
"request");
130 this->handler_.onRequest(this->session());
133template <
class Handler>
137 boost::system::error_code ec;
138 socket_.shutdown(socket_type::shutdown_send, ec);
A generic endpoint for log messages.
Represents an active connection.
void do_read(yield_context do_yield)
beast::Journal journal() override
Port const & port() override
std::shared_ptr< WSSession > websocketUpgrade() override
Convert the connection to WebSocket.
boost::asio::ip::tcp::socket socket_type
boost::asio::ip::tcp::endpoint endpoint_type
boost::beast::tcp_stream stream_type
PlainHTTPPeer(Port const &port, Handler &handler, boost::asio::io_context &ioc, beast::Journal journal, endpoint_type remote_address, ConstBufferSequence const &buffers, stream_type &&stream)
void do_request() override
bool is_keep_alive(boost::beast::http::message< isRequest, Body, Fields > const &m)
void spawn(Ctx &&ctx, F &&func)
Spawns a coroutine using boost::asio::spawn
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Configuration information for a Server listening port.