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>
26#include <boost/beast/core/tcp_stream.hpp>
31template <
class Handler>
46 template <
class ConstBufferSequence>
50 boost::asio::io_context& ioc,
53 ConstBufferSequence
const& buffers,
72template <
class Handler>
73template <
class ConstBufferSequence>
77 boost::asio::io_context& ioc,
80 ConstBufferSequence
const& buffers,
89 , stream_(
std::move(stream))
90 , socket_(stream_.socket())
96 if (remote_endpoint.address().is_loopback())
97 socket_.set_option(boost::asio::ip::tcp::no_delay{
true});
100template <
class Handler>
104 if (!this->handler_.onAccept(this->session(), this->remote_address_))
112 if (!socket_.is_open())
119 this->shared_from_this(),
120 std::placeholders::_1));
123template <
class Handler>
127 auto ws = this->ios().template emplace<PlainWSPeer<Handler>>(
130 this->remote_address_,
131 std::move(this->message_),
137template <
class Handler>
141 ++this->request_count_;
142 auto const what = this->handler_.onHandoff(
143 this->session(), std::move(this->message_), this->remote_address_);
146 boost::system::error_code ec;
150 if (!what.keep_alive)
151 socket_.shutdown(socket_type::shutdown_receive, ec);
153 return this->fail(ec,
"request");
154 return this->write(what.response, what.keep_alive);
159 socket_.shutdown(socket_type::shutdown_receive, ec);
161 return this->fail(ec,
"request");
163 this->handler_.onRequest(this->session());
166template <
class Handler>
170 boost::system::error_code ec;
171 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)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Configuration information for a Server listening port.