1#ifndef XRPL_SERVER_PLAINHTTPPEER_H_INCLUDED
2#define XRPL_SERVER_PLAINHTTPPEER_H_INCLUDED
4#include <xrpl/beast/rfc2616.h>
5#include <xrpl/server/detail/BaseHTTPPeer.h>
6#include <xrpl/server/detail/PlainWSPeer.h>
8#include <boost/beast/core/tcp_stream.hpp>
14template <
class Handler>
29 template <
class ConstBufferSequence>
33 boost::asio::io_context& ioc,
36 ConstBufferSequence
const& buffers,
55template <
class Handler>
56template <
class ConstBufferSequence>
60 boost::asio::io_context& ioc,
63 ConstBufferSequence
const& buffers,
72 , stream_(
std::move(stream))
73 , socket_(stream_.socket())
79 if (remote_endpoint.address().is_loopback())
80 socket_.set_option(boost::asio::ip::tcp::no_delay{
true});
83template <
class Handler>
87 if (!this->handler_.onAccept(this->session(), this->remote_address_))
95 if (!socket_.is_open())
102 this->shared_from_this(),
103 std::placeholders::_1));
106template <
class Handler>
110 auto ws = this->ios().template emplace<PlainWSPeer<Handler>>(
113 this->remote_address_,
114 std::move(this->message_),
120template <
class Handler>
124 ++this->request_count_;
125 auto const what = this->handler_.onHandoff(
126 this->session(), std::move(this->message_), this->remote_address_);
129 boost::system::error_code ec;
133 if (!what.keep_alive)
134 socket_.shutdown(socket_type::shutdown_receive, ec);
136 return this->fail(ec,
"request");
137 return this->write(what.response, what.keep_alive);
142 socket_.shutdown(socket_type::shutdown_receive, ec);
144 return this->fail(ec,
"request");
146 this->handler_.onRequest(this->session());
149template <
class Handler>
153 boost::system::error_code ec;
154 socket_.shutdown(socket_type::shutdown_send, ec);
A generic endpoint for log messages.
Represents an active connection.
Port const & port() override
void do_read(yield_context do_yield)
beast::Journal journal() override
boost::asio::ip::tcp::endpoint endpoint_type
void do_request() override
std::shared_ptr< WSSession > websocketUpgrade() override
Convert the connection to WebSocket.
boost::beast::tcp_stream stream_type
boost::asio::ip::tcp::socket socket_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)
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.