20 #ifndef RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED
21 #define RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED
23 #include <ripple/beast/rfc2616.h>
24 #include <ripple/server/impl/BaseHTTPPeer.h>
25 #include <ripple/server/impl/PlainWSPeer.h>
26 #include <boost/beast/core/tcp_stream.hpp>
31 template<
class Handler>
46 template <
class ConstBufferSequence>
50 boost::asio::io_context& ioc,
53 ConstBufferSequence
const& buffers,
71 template <
class Handler>
72 template <
class ConstBufferSequence>
76 boost::asio::io_context& ioc,
79 ConstBufferSequence
const& buffers,
88 , stream_(
std::move(stream))
89 , socket_(stream_.socket())
95 if(remote_endpoint.address().is_loopback())
96 socket_.set_option(boost::asio::ip::tcp::no_delay{
true});
99 template<
class Handler>
104 if (! this->handler_.onAccept(this->session(), this->remote_address_))
106 boost::asio::spawn(this->strand_,
108 this->shared_from_this()));
112 if (! socket_.is_open())
116 this->shared_from_this(), std::placeholders::_1));
119 template<
class Handler>
124 auto ws = this->ios().template emplace<PlainWSPeer<Handler>>(
125 this->port_, this->handler_, this->remote_address_,
126 std::move(this->message_), std::move(stream_),
131 template<
class Handler>
136 ++this->request_count_;
137 auto const what = this->handler_.onHandoff(this->session(),
138 std::move(this->message_), this->remote_address_);
141 boost::system::error_code ec;
145 if (! what.keep_alive)
146 socket_.shutdown(socket_type::shutdown_receive, ec);
148 return this->fail(ec,
"request");
149 return this->write(what.response, what.keep_alive);
154 socket_.shutdown(socket_type::shutdown_receive, ec);
156 return this->fail(ec,
"request");
158 this->handler_.onRequest(this->session());
161 template<
class Handler>
166 boost::system::error_code ec;
167 socket_.shutdown(socket_type::shutdown_send, ec);