mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Use new beast::http::message:
This commit is contained in:
@@ -301,6 +301,8 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\detail\unit_test\thread.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\detail\write_streambuf.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\handler_alloc.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\basic_headers.hpp">
|
||||
@@ -309,9 +311,7 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\chunk_encode.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\error.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\writes.hpp">
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\basic_parser.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\write_preparation.hpp">
|
||||
</ClInclude>
|
||||
@@ -325,8 +325,6 @@
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\http\impl\basic_parser.ipp">
|
||||
</None>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\impl\http_parser.h">
|
||||
</ClInclude>
|
||||
<None Include="..\..\src\beast\include\beast\http\impl\message.ipp">
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\http\impl\read.ipp">
|
||||
@@ -339,6 +337,8 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\parser.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\parse_error.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\read.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\reason.hpp">
|
||||
@@ -347,16 +347,22 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\rfc2616.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\rfc7230.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\streambuf_body.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\string_body.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\type_check.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\write.hpp">
|
||||
</ClInclude>
|
||||
<None Include="..\..\src\beast\include\beast\impl\basic_streambuf.ipp">
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\consuming_buffers.ipp">
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\prepare_buffers.ipp">
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\static_streambuf.ipp">
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\streambuf_readstream.ipp">
|
||||
</None>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\placeholders.hpp">
|
||||
@@ -375,6 +381,8 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\decorator.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\endian.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\error.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\frame.hpp">
|
||||
@@ -427,11 +435,17 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\teardown.hpp">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\beast\src\beast_http_nodejs_parser.cpp">
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\beast\src\http-parser\http_parser.c">
|
||||
<ClInclude Include="..\..\src\beast\include\beast\write_streambuf.hpp">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\beast\test\http\nodejs-parser\http_parser.c">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\beast\test\http\nodejs-parser\http_parser.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\beast\test\http\nodejs_parser.cpp">
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\beast\test\http\nodejs_parser.hpp">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ed25519-donna\curve25519-donna-32bit.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ed25519-donna\curve25519-donna-64bit.h">
|
||||
|
||||
@@ -478,11 +478,14 @@
|
||||
<Filter Include="sqlite\sqlite">
|
||||
<UniqueIdentifier>{D2A046B6-8986-92AC-082F-15B3A01B8E40}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="src">
|
||||
<UniqueIdentifier>{04C492A5-B8E8-3B1F-4337-A067B40F268A}</UniqueIdentifier>
|
||||
<Filter Include="test">
|
||||
<UniqueIdentifier>{D5859751-012E-81F5-D121-159FE9A25436}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="src\http-parser">
|
||||
<UniqueIdentifier>{1E761797-5D00-57DD-FEBA-D17E07E1788D}</UniqueIdentifier>
|
||||
<Filter Include="test\http">
|
||||
<UniqueIdentifier>{F9ABC269-E86E-1034-C5DE-E9E5B48772DB}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="test\http\nodejs-parser">
|
||||
<UniqueIdentifier>{617863D3-DC6A-1DDA-ACA5-7DC92DCEAFB3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="websocketpp_02">
|
||||
<UniqueIdentifier>{96CE200F-2670-323E-3B37-B90DBC0EDA11}</UniqueIdentifier>
|
||||
@@ -630,6 +633,9 @@
|
||||
<ClInclude Include="..\..\src\beast\include\beast\detail\unit_test\thread.hpp">
|
||||
<Filter>include\beast\detail\unit_test</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\detail\write_streambuf.hpp">
|
||||
<Filter>include\beast\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\handler_alloc.hpp">
|
||||
<Filter>include\beast</Filter>
|
||||
</ClInclude>
|
||||
@@ -642,10 +648,7 @@
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\chunk_encode.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\error.hpp">
|
||||
<Filter>include\beast\http\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\writes.hpp">
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\basic_parser.hpp">
|
||||
<Filter>include\beast\http\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\detail\write_preparation.hpp">
|
||||
@@ -666,9 +669,6 @@
|
||||
<None Include="..\..\src\beast\include\beast\http\impl\basic_parser.ipp">
|
||||
<Filter>include\beast\http\impl</Filter>
|
||||
</None>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\impl\http_parser.h">
|
||||
<Filter>include\beast\http\impl</Filter>
|
||||
</ClInclude>
|
||||
<None Include="..\..\src\beast\include\beast\http\impl\message.ipp">
|
||||
<Filter>include\beast\http\impl</Filter>
|
||||
</None>
|
||||
@@ -687,6 +687,9 @@
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\parser.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\parse_error.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\read.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
@@ -699,21 +702,30 @@
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\rfc2616.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\rfc7230.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\streambuf_body.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\string_body.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\type_check.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\http\write.hpp">
|
||||
<Filter>include\beast\http</Filter>
|
||||
</ClInclude>
|
||||
<None Include="..\..\src\beast\include\beast\impl\basic_streambuf.ipp">
|
||||
<Filter>include\beast\impl</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\consuming_buffers.ipp">
|
||||
<Filter>include\beast\impl</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\prepare_buffers.ipp">
|
||||
<Filter>include\beast\impl</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\static_streambuf.ipp">
|
||||
<Filter>include\beast\impl</Filter>
|
||||
</None>
|
||||
<None Include="..\..\src\beast\include\beast\impl\streambuf_readstream.ipp">
|
||||
<Filter>include\beast\impl</Filter>
|
||||
</None>
|
||||
@@ -741,6 +753,9 @@
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\decorator.hpp">
|
||||
<Filter>include\beast\websocket\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\endian.hpp">
|
||||
<Filter>include\beast\websocket\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\detail\error.hpp">
|
||||
<Filter>include\beast\websocket\detail</Filter>
|
||||
</ClInclude>
|
||||
@@ -819,12 +834,21 @@
|
||||
<ClInclude Include="..\..\src\beast\include\beast\websocket\teardown.hpp">
|
||||
<Filter>include\beast\websocket</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\beast\src\beast_http_nodejs_parser.cpp">
|
||||
<Filter>src</Filter>
|
||||
<ClInclude Include="..\..\src\beast\include\beast\write_streambuf.hpp">
|
||||
<Filter>include\beast</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\beast\test\http\nodejs-parser\http_parser.c">
|
||||
<Filter>test\http\nodejs-parser</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\beast\src\http-parser\http_parser.c">
|
||||
<Filter>src\http-parser</Filter>
|
||||
<ClInclude Include="..\..\src\beast\test\http\nodejs-parser\http_parser.h">
|
||||
<Filter>test\http\nodejs-parser</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\beast\test\http\nodejs_parser.cpp">
|
||||
<Filter>test\http</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\beast\test\http\nodejs_parser.hpp">
|
||||
<Filter>test\http</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ed25519-donna\curve25519-donna-32bit.h">
|
||||
<Filter>ed25519-donna</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -1110,7 +1110,7 @@ for tu_style in ['classic', 'unity']:
|
||||
cc_flags = {}
|
||||
|
||||
object_builder.add_source_files(
|
||||
'src/beast/src/beast_http_nodejs_parser.cpp',
|
||||
'src/beast/test/http/nodejs_parser.cpp',
|
||||
'src/ripple/beast/unity/beast_hash_unity.cpp',
|
||||
'src/ripple/unity/beast.cpp',
|
||||
'src/ripple/unity/lz4.c',
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#include <beast/http/method.hpp>
|
||||
#include <beast/http/headers.hpp>
|
||||
#include <beast/http/basic_parser.hpp>
|
||||
#include <beast/http/detail/writes.hpp>
|
||||
#include <beast/http/rfc2616.hpp>
|
||||
#include <beast/write_streambuf.hpp>
|
||||
#include <beast/test/http/nodejs_parser.hpp>
|
||||
#include <beast/detail/ci_char_traits.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
@@ -340,39 +342,39 @@ write (Streambuf& stream, message const& m)
|
||||
{
|
||||
if (m.request())
|
||||
{
|
||||
http::detail::write (stream, to_string(m.method()));
|
||||
http::detail::write (stream, " ");
|
||||
http::detail::write (stream, m.url());
|
||||
http::detail::write (stream, " HTTP/");
|
||||
http::detail::write (stream, std::to_string(m.version().first));
|
||||
http::detail::write (stream, ".");
|
||||
http::detail::write (stream, std::to_string(m.version().second));
|
||||
beast::write (stream, to_string(m.method()));
|
||||
beast::write (stream, " ");
|
||||
beast::write (stream, m.url());
|
||||
beast::write (stream, " HTTP/");
|
||||
beast::write (stream, std::to_string(m.version().first));
|
||||
beast::write (stream, ".");
|
||||
beast::write (stream, std::to_string(m.version().second));
|
||||
}
|
||||
else
|
||||
{
|
||||
http::detail::write (stream, "HTTP/");
|
||||
http::detail::write (stream, std::to_string(m.version().first));
|
||||
http::detail::write (stream, ".");
|
||||
http::detail::write (stream, std::to_string(m.version().second));
|
||||
http::detail::write (stream, " ");
|
||||
http::detail::write (stream, std::to_string(m.status()));
|
||||
http::detail::write (stream, " ");
|
||||
http::detail::write (stream, m.reason());
|
||||
beast::write (stream, "HTTP/");
|
||||
beast::write (stream, std::to_string(m.version().first));
|
||||
beast::write (stream, ".");
|
||||
beast::write (stream, std::to_string(m.version().second));
|
||||
beast::write (stream, " ");
|
||||
beast::write (stream, std::to_string(m.status()));
|
||||
beast::write (stream, " ");
|
||||
beast::write (stream, m.reason());
|
||||
}
|
||||
http::detail::write (stream, "\r\n");
|
||||
beast::write (stream, "\r\n");
|
||||
write_fields(stream, m.headers);
|
||||
http::detail::write (stream, "\r\n");
|
||||
beast::write (stream, "\r\n");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class parser
|
||||
: public beast::http::basic_parser<parser>
|
||||
: public beast::http::nodejs_basic_parser<parser>
|
||||
{
|
||||
// friend class basic_parser<parser>;
|
||||
|
||||
message& m_;
|
||||
std::function<void(void const*, std::size_t)> write_body_;
|
||||
std::string field_;
|
||||
std::string value_;
|
||||
|
||||
public:
|
||||
parser(parser&&) = default;
|
||||
@@ -388,7 +390,7 @@ public:
|
||||
*/
|
||||
parser(std::function<void(void const*, std::size_t)> write_body,
|
||||
message& m, bool request)
|
||||
: basic_parser(request)
|
||||
: nodejs_basic_parser(request)
|
||||
, m_(m)
|
||||
, write_body_(std::move(write_body))
|
||||
{
|
||||
@@ -396,7 +398,7 @@ public:
|
||||
}
|
||||
|
||||
parser(message& m, body& b, bool request)
|
||||
: basic_parser(request)
|
||||
: nodejs_basic_parser(request)
|
||||
, m_(m)
|
||||
{
|
||||
write_body_ = [&b](void const* data, std::size_t size)
|
||||
@@ -407,6 +409,19 @@ public:
|
||||
}
|
||||
|
||||
//private:
|
||||
|
||||
void flush()
|
||||
{
|
||||
if(! value_.empty())
|
||||
{
|
||||
rfc2616::trim_right_in_place(value_);
|
||||
// VFALCO could std::move
|
||||
m_.headers.insert(field_, value_);
|
||||
field_.clear();
|
||||
value_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
on_start()
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <ripple/overlay/impl/PeerImp.h>
|
||||
#include <ripple/overlay/impl/Tuning.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <beast/http/write.hpp>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -218,48 +219,32 @@ ConnectAttempt::onHandshake (error_code ec)
|
||||
if (! sharedValue)
|
||||
return close(); // makeSharedValue logs
|
||||
|
||||
beast::deprecated_http::message req = makeRequest(
|
||||
! overlay_.peerFinder().config().peerPrivate,
|
||||
req_ = makeRequest(! overlay_.peerFinder().config().peerPrivate,
|
||||
remote_endpoint_.address());
|
||||
auto const hello = buildHello (
|
||||
*sharedValue,
|
||||
overlay_.setup().public_ip,
|
||||
beast::IPAddressConversion::from_asio(remote_endpoint_),
|
||||
app_);
|
||||
appendHello (req.headers, hello);
|
||||
|
||||
beast::deprecated_http::write (write_buf_, req);
|
||||
appendHello (req_.headers, hello);
|
||||
|
||||
setTimer();
|
||||
stream_.async_write_some (write_buf_.data(),
|
||||
beast::http::async_write(stream_, req_,
|
||||
strand_.wrap (std::bind (&ConnectAttempt::onWrite,
|
||||
shared_from_this(), beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred)));
|
||||
shared_from_this(), beast::asio::placeholders::error)));
|
||||
}
|
||||
|
||||
void
|
||||
ConnectAttempt::onWrite (error_code ec, std::size_t bytes_transferred)
|
||||
ConnectAttempt::onWrite (error_code ec)
|
||||
{
|
||||
cancelTimer();
|
||||
|
||||
if(! stream_.next_layer().is_open())
|
||||
return;
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
return;
|
||||
if(ec)
|
||||
return fail("onWrite", ec);
|
||||
JLOG(journal_.trace()) <<
|
||||
"onWrite: " << bytes_transferred << " bytes";
|
||||
|
||||
write_buf_.consume (bytes_transferred);
|
||||
if (write_buf_.size() == 0)
|
||||
return onRead (error_code(), 0);
|
||||
|
||||
setTimer();
|
||||
stream_.async_write_some (write_buf_.data(),
|
||||
strand_.wrap (std::bind (&ConnectAttempt::onWrite,
|
||||
shared_from_this(), beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred)));
|
||||
onRead(error_code(), 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -330,14 +315,15 @@ ConnectAttempt::onShutdown (error_code ec)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
beast::deprecated_http::message
|
||||
auto
|
||||
ConnectAttempt::makeRequest (bool crawl,
|
||||
boost::asio::ip::address const& remote_address)
|
||||
boost::asio::ip::address const& remote_address) ->
|
||||
request_type
|
||||
{
|
||||
beast::deprecated_http::message m;
|
||||
m.method (beast::http::method_t::http_get);
|
||||
m.url ("/");
|
||||
m.version (1, 1);
|
||||
request_type m;
|
||||
m.method = beast::http::method_t::http_get;
|
||||
m.url = "/";
|
||||
m.version = 11;
|
||||
m.headers.insert ("User-Agent", BuildInfo::getFullVersionString());
|
||||
m.headers.insert ("Upgrade", "RTXP/1.2");
|
||||
//std::string("RTXP/") + to_string (BuildInfo::getCurrentProtocol()));
|
||||
|
||||
@@ -28,13 +28,14 @@
|
||||
#include <ripple/overlay/Message.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <beast/placeholders.hpp>
|
||||
#include <ripple/beast/asio/ssl_bundle.h>
|
||||
#include <beast/streambuf.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
#include <beast/placeholders.hpp>
|
||||
#include <beast/streambuf.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/empty_body.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/buffers_iterator.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
@@ -51,8 +52,12 @@ class ConnectAttempt
|
||||
{
|
||||
private:
|
||||
using error_code = boost::system::error_code;
|
||||
|
||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||
|
||||
using request_type =
|
||||
beast::http::request<beast::http::empty_body>;
|
||||
|
||||
Application& app_;
|
||||
std::uint32_t const id_;
|
||||
beast::WrappedSink sink_;
|
||||
@@ -70,6 +75,7 @@ private:
|
||||
beast::streambuf body_;
|
||||
beast::deprecated_http::parser parser_;
|
||||
PeerFinder::Slot::ptr slot_;
|
||||
request_type req_;
|
||||
|
||||
public:
|
||||
ConnectAttempt (Application& app, boost::asio::io_service& io_service,
|
||||
@@ -87,6 +93,7 @@ public:
|
||||
run();
|
||||
|
||||
private:
|
||||
|
||||
void close();
|
||||
void fail (std::string const& reason);
|
||||
void fail (std::string const& name, error_code ec);
|
||||
@@ -95,12 +102,12 @@ private:
|
||||
void onTimer (error_code ec);
|
||||
void onConnect (error_code ec);
|
||||
void onHandshake (error_code ec);
|
||||
void onWrite (error_code ec, std::size_t bytes_transferred);
|
||||
void onWrite (error_code ec);
|
||||
void onRead (error_code ec, std::size_t bytes_transferred);
|
||||
void onShutdown (error_code ec);
|
||||
|
||||
static
|
||||
beast::deprecated_http::message
|
||||
request_type
|
||||
makeRequest (bool crawl,
|
||||
boost::asio::ip::address const& remote_address);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define RIPPLE_SERVER_HANDOFF_H_INCLUDED
|
||||
|
||||
#include <ripple/server/Writer.h>
|
||||
#include <ripple/beast/deprecated_http.h>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/streambuf_body.hpp>
|
||||
#include <memory>
|
||||
@@ -30,6 +31,9 @@ namespace ripple {
|
||||
using http_request_type =
|
||||
beast::http::request<beast::http::streambuf_body>;
|
||||
|
||||
using http_response_type =
|
||||
beast::deprecated_http::message;
|
||||
|
||||
/** Used to indicate the result of a server connection handoff. */
|
||||
struct Handoff
|
||||
{
|
||||
|
||||
@@ -155,7 +155,7 @@ make_JsonWriter (beast::deprecated_http::message& m, Json::Value const& json)
|
||||
m.headers.insert("Content-Length", std::to_string(body.size()));
|
||||
m.headers.erase ("Content-Type");
|
||||
m.headers.insert("Content-Type", "application/json");
|
||||
write(prebody, m);
|
||||
beast::deprecated_http::write(prebody, m);
|
||||
return std::make_shared<streambufs_writer>(
|
||||
std::move(prebody), std::move(body));
|
||||
}
|
||||
|
||||
@@ -85,11 +85,6 @@ public:
|
||||
virtual
|
||||
Setup const&
|
||||
setup() const = 0;
|
||||
|
||||
/** Fills in boilerplate HTTP header field values. */
|
||||
static
|
||||
void
|
||||
appendStandardFields (beast::deprecated_http::message& message);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <ripple/server/Writer.h>
|
||||
#include <ripple/beast/deprecated_http.h>
|
||||
#include <beast/streambuf.hpp>
|
||||
#include <beast/write_streambuf.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace ripple {
|
||||
@@ -96,8 +97,8 @@ private:
|
||||
message_.headers.erase("Content-Length");
|
||||
message_.headers.insert("Content-Length",
|
||||
std::to_string(body_.size()));
|
||||
write(streambuf_, message_);
|
||||
beast::http::detail::write(streambuf_, body_);
|
||||
beast::deprecated_http::write(streambuf_, message_);
|
||||
beast::write(streambuf_, body_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -687,13 +687,6 @@ ServerHandlerImp::authorized (Port const& port,
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
ServerHandler::appendStandardFields (beast::deprecated_http::message& message)
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
ServerHandler::Setup::makeContexts()
|
||||
{
|
||||
|
||||
@@ -23,8 +23,11 @@
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <beast/streambuf.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/streambuf_body.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <string>
|
||||
|
||||
@@ -69,17 +72,19 @@ class JSONRPCClient : public AbstractClient
|
||||
return s;
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::endpoint ep_;
|
||||
boost::asio::io_service ios_;
|
||||
boost::asio::ip::tcp::socket stream_;
|
||||
boost::asio::streambuf bin_;
|
||||
beast::streambuf bin_;
|
||||
beast::streambuf bout_;
|
||||
|
||||
public:
|
||||
explicit
|
||||
JSONRPCClient(Config const& cfg)
|
||||
: stream_(ios_)
|
||||
: ep_(getEndpoint(cfg))
|
||||
, stream_(ios_)
|
||||
{
|
||||
stream_.connect(getEndpoint(cfg));
|
||||
stream_.connect(ep_);
|
||||
}
|
||||
|
||||
~JSONRPCClient() override
|
||||
@@ -98,7 +103,17 @@ public:
|
||||
invoke(std::string const& cmd,
|
||||
Json::Value const& params) override
|
||||
{
|
||||
std::string s;
|
||||
using namespace beast::http;
|
||||
using namespace boost::asio;
|
||||
using namespace std::string_literals;
|
||||
|
||||
request<string_body> req;
|
||||
req.method = method_t::http_post;
|
||||
req.url = "/";
|
||||
req.version = 11;
|
||||
req.headers.insert("Content-Type", "application/json; charset=UTF-8");
|
||||
req.headers.insert("Host",
|
||||
ep_.address().to_string() + ":" + std::to_string(ep_.port()));
|
||||
{
|
||||
Json::Value jr;
|
||||
jr["method"] = cmd;
|
||||
@@ -107,47 +122,16 @@ public:
|
||||
Json::Value& ja = jr["params"] = Json::arrayValue;
|
||||
ja.append(params);
|
||||
}
|
||||
s = to_string(jr);
|
||||
req.body = to_string(jr);
|
||||
}
|
||||
write(stream_, req);
|
||||
|
||||
using namespace boost::asio;
|
||||
using namespace std::string_literals;
|
||||
auto const r =
|
||||
"POST / HTTP/1.1\r\n"
|
||||
"Host: me\r\n"
|
||||
"Connection: Keep-Alive\r\n"s +
|
||||
"Content-Type: application/json; charset=UTF-8\r\n"s +
|
||||
"Content-Length: " + std::to_string(s.size()) + "\r\n"
|
||||
"\r\n" + s;
|
||||
write(stream_, buffer(r));
|
||||
|
||||
read_until(stream_, bin_, "\r\n\r\n");
|
||||
beast::streambuf body;
|
||||
beast::deprecated_http::message m;
|
||||
beast::deprecated_http::parser p(
|
||||
[&](void const* data, std::size_t size)
|
||||
{
|
||||
body.commit(buffer_copy(
|
||||
body.prepare(size), const_buffer(data, size)));
|
||||
}, m, false);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
auto used = p.write(bin_.data(), ec);
|
||||
if(ec)
|
||||
Throw<boost::system::system_error>(ec);
|
||||
bin_.consume(used);
|
||||
// VFALCO What do we do if bin_ still has data?
|
||||
if(p.complete())
|
||||
break;
|
||||
bin_.commit(stream_.read_some(
|
||||
bin_.prepare(1024)));
|
||||
}
|
||||
response<streambuf_body> res;
|
||||
read(stream_, bin_, res);
|
||||
|
||||
Json::Reader jr;
|
||||
Json::Value jv;
|
||||
jr.parse(buffer_string(body.data()), jv);
|
||||
jr.parse(buffer_string(res.body.data()), jv);
|
||||
if(jv["result"].isMember("error"))
|
||||
jv["error"] = jv["result"]["error"];
|
||||
if(jv["result"].isMember("status"))
|
||||
|
||||
Reference in New Issue
Block a user