20#ifndef RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED
21#define RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED
23#include <xrpl/beast/rfc2616.h>
24#include <xrpl/server/detail/BaseHTTPPeer.h>
25#include <xrpl/server/detail/PlainWSPeer.h>
27#include <boost/beast/core/tcp_stream.hpp>
33template <
class Handler>
48 template <
class ConstBufferSequence>
52 boost::asio::io_context& ioc,
55 ConstBufferSequence
const& buffers,
74template <
class Handler>
75template <
class ConstBufferSequence>
79 boost::asio::io_context& ioc,
82 ConstBufferSequence
const& buffers,
91 , stream_(
std::move(stream))
92 , socket_(stream_.socket())
98 if (remote_endpoint.address().is_loopback())
99 socket_.set_option(boost::asio::ip::tcp::no_delay{
true});
102template <
class Handler>
106 if (!this->handler_.onAccept(this->session(), this->remote_address_))
114 if (!socket_.is_open())
121 this->shared_from_this(),
122 std::placeholders::_1));
125template <
class Handler>
129 auto ws = this->ios().template emplace<PlainWSPeer<Handler>>(
132 this->remote_address_,
133 std::move(this->message_),
139template <
class Handler>
143 ++this->request_count_;
144 auto const what = this->handler_.onHandoff(
145 this->session(), std::move(this->message_), this->remote_address_);
148 boost::system::error_code ec;
152 if (!what.keep_alive)
153 socket_.shutdown(socket_type::shutdown_receive, ec);
155 return this->fail(ec,
"request");
156 return this->write(what.response, what.keep_alive);
161 socket_.shutdown(socket_type::shutdown_receive, ec);
163 return this->fail(ec,
"request");
165 this->handler_.onRequest(this->session());
168template <
class Handler>
172 boost::system::error_code ec;
173 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.