mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Update for Beast changes
This commit is contained in:
@@ -221,7 +221,7 @@ ConnectAttempt::onHandshake (error_code ec)
|
|||||||
overlay_.setup().public_ip,
|
overlay_.setup().public_ip,
|
||||||
beast::IPAddressConversion::from_asio(remote_endpoint_),
|
beast::IPAddressConversion::from_asio(remote_endpoint_),
|
||||||
app_);
|
app_);
|
||||||
appendHello (req_.headers, hello);
|
appendHello (req_.fields, hello);
|
||||||
|
|
||||||
setTimer();
|
setTimer();
|
||||||
beast::http::async_write(stream_, req_,
|
beast::http::async_write(stream_, req_,
|
||||||
@@ -293,12 +293,12 @@ ConnectAttempt::makeRequest (bool crawl,
|
|||||||
m.method = "GET";
|
m.method = "GET";
|
||||||
m.url = "/";
|
m.url = "/";
|
||||||
m.version = 11;
|
m.version = 11;
|
||||||
m.headers.insert ("User-Agent", BuildInfo::getFullVersionString());
|
m.fields.insert ("User-Agent", BuildInfo::getFullVersionString());
|
||||||
m.headers.insert ("Upgrade", "RTXP/1.2");
|
m.fields.insert ("Upgrade", "RTXP/1.2");
|
||||||
//std::string("RTXP/") + to_string (BuildInfo::getCurrentProtocol()));
|
//std::string("RTXP/") + to_string (BuildInfo::getCurrentProtocol()));
|
||||||
m.headers.insert ("Connection", "Upgrade");
|
m.fields.insert ("Connection", "Upgrade");
|
||||||
m.headers.insert ("Connect-As", "Peer");
|
m.fields.insert ("Connect-As", "Peer");
|
||||||
m.headers.insert ("Crawl", crawl ? "public" : "private");
|
m.fields.insert ("Crawl", crawl ? "public" : "private");
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ ConnectAttempt::processResponse()
|
|||||||
return close();
|
return close();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hello = parseHello (false, response_.headers, journal_);
|
auto hello = parseHello (false, response_.fields, journal_);
|
||||||
if(! hello)
|
if(! hello)
|
||||||
return fail("processResponse: Bad TMHello");
|
return fail("processResponse: Bad TMHello");
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#include <ripple/beast/utility/WrappedSink.h>
|
#include <ripple/beast/utility/WrappedSink.h>
|
||||||
#include <beast/core/placeholders.hpp>
|
#include <beast/core/placeholders.hpp>
|
||||||
#include <beast/core/streambuf.hpp>
|
#include <beast/core/streambuf.hpp>
|
||||||
#include <beast/http/message_v1.hpp>
|
#include <beast/http/message.hpp>
|
||||||
#include <beast/http/empty_body.hpp>
|
#include <beast/http/empty_body.hpp>
|
||||||
#include <beast/http/parser_v1.hpp>
|
#include <beast/http/parser_v1.hpp>
|
||||||
#include <boost/asio/basic_waitable_timer.hpp>
|
#include <boost/asio/basic_waitable_timer.hpp>
|
||||||
@@ -56,10 +56,10 @@ private:
|
|||||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||||
|
|
||||||
using request_type =
|
using request_type =
|
||||||
beast::http::request_v1<beast::http::empty_body>;
|
beast::http::request<beast::http::empty_body>;
|
||||||
|
|
||||||
using response_type =
|
using response_type =
|
||||||
beast::http::response_v1<beast::http::streambuf_body>;
|
beast::http::response<beast::http::streambuf_body>;
|
||||||
|
|
||||||
Application& app_;
|
Application& app_;
|
||||||
std::uint32_t const id_;
|
std::uint32_t const id_;
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto const types = beast::rfc2616::split_commas(
|
auto const types = beast::rfc2616::split_commas(
|
||||||
request.headers["Connect-As"]);
|
request.fields["Connect-As"]);
|
||||||
if (std::find_if(types.begin(), types.end(),
|
if (std::find_if(types.begin(), types.end(),
|
||||||
[](std::string const& s)
|
[](std::string const& s)
|
||||||
{
|
{
|
||||||
@@ -234,7 +234,7 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hello = parseHello (true, request.headers, journal);
|
auto hello = parseHello (true, request.fields, journal);
|
||||||
if(! hello)
|
if(! hello)
|
||||||
{
|
{
|
||||||
m_peerFinder->on_closed(slot);
|
m_peerFinder->on_closed(slot);
|
||||||
@@ -319,7 +319,7 @@ OverlayImpl::isPeerUpgrade(http_request_type const& request)
|
|||||||
if (! is_upgrade(request))
|
if (! is_upgrade(request))
|
||||||
return false;
|
return false;
|
||||||
auto const versions = parse_ProtocolVersions(
|
auto const versions = parse_ProtocolVersions(
|
||||||
request.headers["Upgrade"]);
|
request.fields["Upgrade"]);
|
||||||
if (versions.size() == 0)
|
if (versions.size() == 0)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -333,7 +333,7 @@ OverlayImpl::isPeerUpgrade(http_response_type const& response)
|
|||||||
if(response.status != 101)
|
if(response.status != 101)
|
||||||
return false;
|
return false;
|
||||||
auto const versions = parse_ProtocolVersions(
|
auto const versions = parse_ProtocolVersions(
|
||||||
response.headers["Upgrade"]);
|
response.fields["Upgrade"]);
|
||||||
if (versions.size() == 0)
|
if (versions.size() == 0)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -351,13 +351,13 @@ std::shared_ptr<Writer>
|
|||||||
OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot,
|
OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot,
|
||||||
http_request_type const& request, address_type remote_address)
|
http_request_type const& request, address_type remote_address)
|
||||||
{
|
{
|
||||||
beast::http::response_v1<json_body> msg;
|
beast::http::response<json_body> msg;
|
||||||
msg.version = request.version;
|
msg.version = request.version;
|
||||||
msg.status = 503;
|
msg.status = 503;
|
||||||
msg.reason = "Service Unavailable";
|
msg.reason = "Service Unavailable";
|
||||||
msg.headers.insert("Server", BuildInfo::getFullVersionString());
|
msg.fields.insert("Server", BuildInfo::getFullVersionString());
|
||||||
msg.headers.insert("Remote-Address", remote_address.to_string());
|
msg.fields.insert("Remote-Address", remote_address.to_string());
|
||||||
msg.headers.insert("Content-Type", "application/json");
|
msg.fields.insert("Content-Type", "application/json");
|
||||||
msg.body = Json::objectValue;
|
msg.body = Json::objectValue;
|
||||||
{
|
{
|
||||||
auto const result = m_peerFinder->redirect(slot);
|
auto const result = m_peerFinder->redirect(slot);
|
||||||
@@ -375,12 +375,12 @@ OverlayImpl::makeErrorResponse (PeerFinder::Slot::ptr const& slot,
|
|||||||
address_type remote_address,
|
address_type remote_address,
|
||||||
std::string text)
|
std::string text)
|
||||||
{
|
{
|
||||||
beast::http::response_v1<beast::http::string_body> msg;
|
beast::http::response<beast::http::string_body> msg;
|
||||||
msg.version = request.version;
|
msg.version = request.version;
|
||||||
msg.status = 400;
|
msg.status = 400;
|
||||||
msg.reason = "Bad Request";
|
msg.reason = "Bad Request";
|
||||||
msg.headers.insert("Server", BuildInfo::getFullVersionString());
|
msg.fields.insert("Server", BuildInfo::getFullVersionString());
|
||||||
msg.headers.insert("Remote-Address", remote_address.to_string());
|
msg.fields.insert("Remote-Address", remote_address.to_string());
|
||||||
msg.body = text;
|
msg.body = text;
|
||||||
prepare(msg, beast::http::connection::close);
|
prepare(msg, beast::http::connection::close);
|
||||||
return std::make_shared<SimpleWriter>(msg);
|
return std::make_shared<SimpleWriter>(msg);
|
||||||
@@ -873,12 +873,12 @@ OverlayImpl::processRequest (http_request_type const& req,
|
|||||||
if (req.url != "/crawl")
|
if (req.url != "/crawl")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beast::http::response_v1<json_body> msg;
|
beast::http::response<json_body> msg;
|
||||||
msg.version = req.version;
|
msg.version = req.version;
|
||||||
msg.status = 200;
|
msg.status = 200;
|
||||||
msg.reason = "OK";
|
msg.reason = "OK";
|
||||||
msg.headers.insert("Server", BuildInfo::getFullVersionString());
|
msg.fields.insert("Server", BuildInfo::getFullVersionString());
|
||||||
msg.headers.insert("Content-Type", "application/json");
|
msg.fields.insert("Content-Type", "application/json");
|
||||||
msg.body["overlay"] = crawl();
|
msg.body["overlay"] = crawl();
|
||||||
prepare(msg, beast::http::connection::close);
|
prepare(msg, beast::http::connection::close);
|
||||||
handoff.response = std::make_shared<SimpleWriter>(msg);
|
handoff.response = std::make_shared<SimpleWriter>(msg);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ PeerImp::PeerImp (Application& app, id_t id, endpoint_type remote_endpoint,
|
|||||||
, fee_ (Resource::feeLightPeer)
|
, fee_ (Resource::feeLightPeer)
|
||||||
, slot_ (slot)
|
, slot_ (slot)
|
||||||
, request_(std::move(request))
|
, request_(std::move(request))
|
||||||
, headers_(request_.headers)
|
, headers_(request_.fields)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,14 +652,14 @@ PeerImp::makeResponse (bool crawl,
|
|||||||
resp.status = 101;
|
resp.status = 101;
|
||||||
resp.reason = "Switching Protocols";
|
resp.reason = "Switching Protocols";
|
||||||
resp.version = req.version;
|
resp.version = req.version;
|
||||||
resp.headers.insert("Connection", "Upgrade");
|
resp.fields.insert("Connection", "Upgrade");
|
||||||
resp.headers.insert("Upgrade", "RTXP/1.2");
|
resp.fields.insert("Upgrade", "RTXP/1.2");
|
||||||
resp.headers.insert("Connect-AS", "Peer");
|
resp.fields.insert("Connect-AS", "Peer");
|
||||||
resp.headers.insert("Server", BuildInfo::getFullVersionString());
|
resp.fields.insert("Server", BuildInfo::getFullVersionString());
|
||||||
resp.headers.insert("Crawl", crawl ? "public" : "private");
|
resp.fields.insert("Crawl", crawl ? "public" : "private");
|
||||||
protocol::TMHello hello = buildHello(sharedValue,
|
protocol::TMHello hello = buildHello(sharedValue,
|
||||||
overlay_.setup().public_ip, remote, app_);
|
overlay_.setup().public_ip, remote, app_);
|
||||||
appendHello(resp.headers, hello);
|
appendHello(resp.fields, hello);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ private:
|
|||||||
beast::streambuf read_buffer_;
|
beast::streambuf read_buffer_;
|
||||||
http_request_type request_;
|
http_request_type request_;
|
||||||
http_response_type response_;
|
http_response_type response_;
|
||||||
beast::http::headers const& headers_;
|
beast::http::fields const& headers_;
|
||||||
beast::streambuf write_buffer_;
|
beast::streambuf write_buffer_;
|
||||||
std::queue<Message::pointer> send_queue_;
|
std::queue<Message::pointer> send_queue_;
|
||||||
bool gracefulClose_ = false;
|
bool gracefulClose_ = false;
|
||||||
@@ -502,7 +502,7 @@ PeerImp::PeerImp (Application& app, std::unique_ptr<beast::asio::ssl_bundle>&& s
|
|||||||
, fee_ (Resource::feeLightPeer)
|
, fee_ (Resource::feeLightPeer)
|
||||||
, slot_ (std::move(slot))
|
, slot_ (std::move(slot))
|
||||||
, response_(std::move(response))
|
, response_(std::move(response))
|
||||||
, headers_(response_.headers)
|
, headers_(response_.fields)
|
||||||
{
|
{
|
||||||
read_buffer_.commit (boost::asio::buffer_copy(read_buffer_.prepare(
|
read_buffer_.commit (boost::asio::buffer_copy(read_buffer_.prepare(
|
||||||
boost::asio::buffer_size(buffers)), buffers));
|
boost::asio::buffer_size(buffers)), buffers));
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ buildHello (
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
appendHello (beast::http::headers& h,
|
appendHello (beast::http::fields& h,
|
||||||
protocol::TMHello const& hello)
|
protocol::TMHello const& hello)
|
||||||
{
|
{
|
||||||
//h.append ("Protocol-Versions",...
|
//h.append ("Protocol-Versions",...
|
||||||
@@ -222,7 +222,7 @@ parse_ProtocolVersions(boost::string_ref const& value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<protocol::TMHello>
|
boost::optional<protocol::TMHello>
|
||||||
parseHello (bool request, beast::http::headers const& h, beast::Journal journal)
|
parseHello (bool request, beast::http::fields const& h, beast::Journal journal)
|
||||||
{
|
{
|
||||||
// protocol version in TMHello is obsolete,
|
// protocol version in TMHello is obsolete,
|
||||||
// it is supplanted by the values in the headers.
|
// it is supplanted by the values in the headers.
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <ripple/protocol/BuildInfo.h>
|
#include <ripple/protocol/BuildInfo.h>
|
||||||
#include <ripple/protocol/PublicKey.h>
|
#include <ripple/protocol/PublicKey.h>
|
||||||
#include <ripple/protocol/UintTypes.h>
|
#include <ripple/protocol/UintTypes.h>
|
||||||
#include <beast/http/headers.hpp>
|
|
||||||
#include <beast/http/message.hpp>
|
#include <beast/http/message.hpp>
|
||||||
#include <ripple/beast/utility/Journal.h>
|
#include <ripple/beast/utility/Journal.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -59,14 +58,14 @@ buildHello (uint256 const& sharedValue,
|
|||||||
|
|
||||||
/** Insert HTTP headers based on the TMHello protocol message. */
|
/** Insert HTTP headers based on the TMHello protocol message. */
|
||||||
void
|
void
|
||||||
appendHello (beast::http::headers& h, protocol::TMHello const& hello);
|
appendHello (beast::http::fields& h, protocol::TMHello const& hello);
|
||||||
|
|
||||||
/** Parse HTTP headers into TMHello protocol message.
|
/** Parse HTTP headers into TMHello protocol message.
|
||||||
@return A protocol message on success; an empty optional
|
@return A protocol message on success; an empty optional
|
||||||
if the parsing failed.
|
if the parsing failed.
|
||||||
*/
|
*/
|
||||||
boost::optional<protocol::TMHello>
|
boost::optional<protocol::TMHello>
|
||||||
parseHello (bool request, beast::http::headers const& h, beast::Journal journal);
|
parseHello (bool request, beast::http::fields const& h, beast::Journal journal);
|
||||||
|
|
||||||
/** Validate and store the public key in the TMHello.
|
/** Validate and store the public key in the TMHello.
|
||||||
This includes signature verification on the shared value.
|
This includes signature verification on the shared value.
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
#include <ripple/rpc/RPCHandler.h>
|
#include <ripple/rpc/RPCHandler.h>
|
||||||
#include <ripple/server/SimpleWriter.h>
|
#include <ripple/server/SimpleWriter.h>
|
||||||
#include <beast/core/detail/base64.hpp>
|
#include <beast/core/detail/base64.hpp>
|
||||||
#include <beast/http/headers.hpp>
|
#include <beast/http/fields.hpp>
|
||||||
#include <beast/http/string_body.hpp>
|
#include <beast/http/string_body.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
@@ -61,7 +61,7 @@ isWebsocketUpgrade(
|
|||||||
{
|
{
|
||||||
if (is_upgrade(request))
|
if (is_upgrade(request))
|
||||||
return beast::detail::ci_equal(
|
return beast::detail::ci_equal(
|
||||||
request.headers["Upgrade"], "websocket");
|
request.fields["Upgrade"], "websocket");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,19 +81,19 @@ unauthorizedResponse(
|
|||||||
{
|
{
|
||||||
using namespace beast::http;
|
using namespace beast::http;
|
||||||
Handoff handoff;
|
Handoff handoff;
|
||||||
response_v1<string_body> msg;
|
response<string_body> msg;
|
||||||
msg.version = request.version;
|
msg.version = request.version;
|
||||||
msg.status = 401;
|
msg.status = 401;
|
||||||
msg.reason = "Unauthorized";
|
msg.reason = "Unauthorized";
|
||||||
msg.headers.insert("Server", BuildInfo::getFullVersionString());
|
msg.fields.insert("Server", BuildInfo::getFullVersionString());
|
||||||
msg.headers.insert("Content-Type", "text/html");
|
msg.fields.insert("Content-Type", "text/html");
|
||||||
msg.body = "Invalid protocol.";
|
msg.body = "Invalid protocol.";
|
||||||
prepare(msg, beast::http::connection::close);
|
prepare(msg, beast::http::connection::close);
|
||||||
handoff.response = std::make_shared<SimpleWriter>(msg);
|
handoff.response = std::make_shared<SimpleWriter>(msg);
|
||||||
return handoff;
|
return handoff;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VFALCO TODO Rewrite to use beast::http::headers
|
// VFALCO TODO Rewrite to use beast::http::fields
|
||||||
static
|
static
|
||||||
bool
|
bool
|
||||||
authorized (
|
authorized (
|
||||||
@@ -269,7 +269,7 @@ Json::Output makeOutput (Session& session)
|
|||||||
// HACK!
|
// HACK!
|
||||||
static
|
static
|
||||||
std::map<std::string, std::string>
|
std::map<std::string, std::string>
|
||||||
build_map(beast::http::headers const& h)
|
build_map(beast::http::fields const& h)
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> c;
|
std::map <std::string, std::string> c;
|
||||||
for (auto const& e : h)
|
for (auto const& e : h)
|
||||||
@@ -311,7 +311,7 @@ ServerHandlerImp::onRequest (Session& session)
|
|||||||
|
|
||||||
// Check user/password authorization
|
// Check user/password authorization
|
||||||
if (! authorized (
|
if (! authorized (
|
||||||
session.port(), build_map(session.request().headers)))
|
session.port(), build_map(session.request().fields)))
|
||||||
{
|
{
|
||||||
HTTPReply (403, "Forbidden", makeOutput (session), app_.journal ("RPC"));
|
HTTPReply (403, "Forbidden", makeOutput (session), app_.journal ("RPC"));
|
||||||
session.close (true);
|
session.close (true);
|
||||||
@@ -507,18 +507,18 @@ ServerHandlerImp::processSession (std::shared_ptr<Session> const& session,
|
|||||||
[&]
|
[&]
|
||||||
{
|
{
|
||||||
auto const iter =
|
auto const iter =
|
||||||
session->request().headers.find(
|
session->request().fields.find(
|
||||||
"X-Forwarded-For");
|
"X-Forwarded-For");
|
||||||
if(iter != session->request().headers.end())
|
if(iter != session->request().fields.end())
|
||||||
return iter->second;
|
return iter->second;
|
||||||
return std::string{};
|
return std::string{};
|
||||||
}(),
|
}(),
|
||||||
[&]
|
[&]
|
||||||
{
|
{
|
||||||
auto const iter =
|
auto const iter =
|
||||||
session->request().headers.find(
|
session->request().fields.find(
|
||||||
"X-User");
|
"X-User");
|
||||||
if(iter != session->request().headers.end())
|
if(iter != session->request().fields.end())
|
||||||
return iter->second;
|
return iter->second;
|
||||||
return std::string{};
|
return std::string{};
|
||||||
}());
|
}());
|
||||||
@@ -728,7 +728,7 @@ ServerHandlerImp::statusResponse(
|
|||||||
{
|
{
|
||||||
using namespace beast::http;
|
using namespace beast::http;
|
||||||
Handoff handoff;
|
Handoff handoff;
|
||||||
response_v1<string_body> msg;
|
response<string_body> msg;
|
||||||
std::string reason;
|
std::string reason;
|
||||||
if (app_.serverOkay(reason))
|
if (app_.serverOkay(reason))
|
||||||
{
|
{
|
||||||
@@ -747,8 +747,8 @@ ServerHandlerImp::statusResponse(
|
|||||||
reason + "</BODY></HTML>";
|
reason + "</BODY></HTML>";
|
||||||
}
|
}
|
||||||
msg.version = request.version;
|
msg.version = request.version;
|
||||||
msg.headers.insert("Server", BuildInfo::getFullVersionString());
|
msg.fields.insert("Server", BuildInfo::getFullVersionString());
|
||||||
msg.headers.insert("Content-Type", "text/html");
|
msg.fields.insert("Content-Type", "text/html");
|
||||||
prepare(msg, beast::http::connection::close);
|
prepare(msg, beast::http::connection::close);
|
||||||
handoff.response = std::make_shared<SimpleWriter>(msg);
|
handoff.response = std::make_shared<SimpleWriter>(msg);
|
||||||
return handoff;
|
return handoff;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
: InfoSub(source)
|
: InfoSub(source)
|
||||||
, ws_(ws)
|
, ws_(ws)
|
||||||
{
|
{
|
||||||
auto const& h = ws->request().headers;
|
auto const& h = ws->request().fields;
|
||||||
auto it = h.find("X-User");
|
auto it = h.find("X-User");
|
||||||
if (it != h.end() &&
|
if (it != h.end() &&
|
||||||
isIdentified(
|
isIdentified(
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include <ripple/json/json_value.h>
|
#include <ripple/json/json_value.h>
|
||||||
#include <beast/core/streambuf.hpp>
|
#include <beast/core/streambuf.hpp>
|
||||||
#include <beast/http/body_type.hpp>
|
#include <beast/http/message.hpp>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
@@ -36,10 +36,10 @@ struct json_body
|
|||||||
beast::streambuf sb_;
|
beast::streambuf sb_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template<bool isRequest, class Headers>
|
template<bool isRequest, class Fields>
|
||||||
explicit
|
explicit
|
||||||
writer(beast::http::message<
|
writer(beast::http::message<
|
||||||
isRequest, json_body, Headers> const& m)
|
isRequest, json_body, Fields> const& m) noexcept
|
||||||
{
|
{
|
||||||
stream(m.body,
|
stream(m.body,
|
||||||
[&](void const* data, std::size_t n)
|
[&](void const* data, std::size_t n)
|
||||||
@@ -50,22 +50,22 @@ struct json_body
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init(beast::error_code&)
|
init(beast::error_code&) noexcept
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t
|
std::uint64_t
|
||||||
content_length() const
|
content_length() const noexcept
|
||||||
{
|
{
|
||||||
return sb_.size();
|
return sb_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Write>
|
template<class Writef>
|
||||||
boost::tribool
|
boost::tribool
|
||||||
operator()(beast::http::resume_context&&,
|
write(beast::http::resume_context&&,
|
||||||
beast::error_code&, Write&& write)
|
beast::error_code&, Writef&& wf) noexcept
|
||||||
{
|
{
|
||||||
write(sb_.data());
|
wf(sb_.data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,17 +21,17 @@
|
|||||||
#define RIPPLE_SERVER_HANDOFF_H_INCLUDED
|
#define RIPPLE_SERVER_HANDOFF_H_INCLUDED
|
||||||
|
|
||||||
#include <ripple/server/Writer.h>
|
#include <ripple/server/Writer.h>
|
||||||
#include <beast/http/message_v1.hpp>
|
#include <beast/http/message.hpp>
|
||||||
#include <beast/http/streambuf_body.hpp>
|
#include <beast/http/streambuf_body.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
using http_request_type =
|
using http_request_type =
|
||||||
beast::http::request_v1<beast::http::streambuf_body>;
|
beast::http::request<beast::http::streambuf_body>;
|
||||||
|
|
||||||
using http_response_type =
|
using http_response_type =
|
||||||
beast::http::response_v1<beast::http::streambuf_body>;
|
beast::http::response<beast::http::streambuf_body>;
|
||||||
|
|
||||||
/** Used to indicate the result of a server connection handoff. */
|
/** Used to indicate the result of a server connection handoff. */
|
||||||
struct Handoff
|
struct Handoff
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include <ripple/server/Writer.h>
|
#include <ripple/server/Writer.h>
|
||||||
#include <beast/core/streambuf.hpp>
|
#include <beast/core/streambuf.hpp>
|
||||||
#include <beast/core/write_dynabuf.hpp>
|
#include <beast/core/write_dynabuf.hpp>
|
||||||
#include <beast/http/message_v1.hpp>
|
#include <beast/http/message.hpp>
|
||||||
#include <beast/http/write.hpp>
|
#include <beast/http/write.hpp>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class SimpleWriter : public Writer
|
|||||||
public:
|
public:
|
||||||
template<bool isRequest, class Body, class Headers>
|
template<bool isRequest, class Body, class Headers>
|
||||||
explicit
|
explicit
|
||||||
SimpleWriter(beast::http::message_v1<
|
SimpleWriter(beast::http::message<
|
||||||
isRequest, Body, Headers> const& msg)
|
isRequest, Body, Headers> const& msg)
|
||||||
{
|
{
|
||||||
beast::write(sb_, msg);
|
beast::write(sb_, msg);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <ripple/protocol/BuildInfo.h>
|
#include <ripple/protocol/BuildInfo.h>
|
||||||
#include <beast/websocket.hpp>
|
#include <beast/websocket.hpp>
|
||||||
#include <beast/core/streambuf.hpp>
|
#include <beast/core/streambuf.hpp>
|
||||||
#include <beast/http/message_v1.hpp>
|
#include <beast/http/message.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
Port const& port,
|
Port const& port,
|
||||||
Handler& handler,
|
Handler& handler,
|
||||||
endpoint_type remote_address,
|
endpoint_type remote_address,
|
||||||
beast::http::request_v1<Body, Headers>&& request,
|
beast::http::request<Body, Headers>&& request,
|
||||||
boost::asio::io_service& io_service,
|
boost::asio::io_service& io_service,
|
||||||
beast::Journal journal);
|
beast::Journal journal);
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ protected:
|
|||||||
void
|
void
|
||||||
operator()(beast::http::message<true, Body, Headers>& req)
|
operator()(beast::http::message<true, Body, Headers>& req)
|
||||||
{
|
{
|
||||||
req.headers.replace("User-Agent",
|
req.fields.replace("User-Agent",
|
||||||
BuildInfo::getFullVersionString());
|
BuildInfo::getFullVersionString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ protected:
|
|||||||
void
|
void
|
||||||
operator()(beast::http::message<false, Body, Headers>& resp)
|
operator()(beast::http::message<false, Body, Headers>& resp)
|
||||||
{
|
{
|
||||||
resp.headers.replace("Server",
|
resp.fields.replace("Server",
|
||||||
BuildInfo::getFullVersionString());
|
BuildInfo::getFullVersionString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -175,7 +175,7 @@ BaseWSPeer(
|
|||||||
Port const& port,
|
Port const& port,
|
||||||
Handler& handler,
|
Handler& handler,
|
||||||
endpoint_type remote_address,
|
endpoint_type remote_address,
|
||||||
beast::http::request_v1<Body, Headers>&& request,
|
beast::http::request<Body, Headers>&& request,
|
||||||
boost::asio::io_service& io_service,
|
boost::asio::io_service& io_service,
|
||||||
beast::Journal journal)
|
beast::Journal journal)
|
||||||
: BasePeer<Handler, Impl>(port, handler, remote_address,
|
: BasePeer<Handler, Impl>(port, handler, remote_address,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
Port const& port,
|
Port const& port,
|
||||||
Handler& handler,
|
Handler& handler,
|
||||||
endpoint_type remote_address,
|
endpoint_type remote_address,
|
||||||
beast::http::request_v1<Body, Headers>&& request,
|
beast::http::request<Body, Headers>&& request,
|
||||||
socket_type&& socket,
|
socket_type&& socket,
|
||||||
beast::Journal journal);
|
beast::Journal journal);
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ PlainWSPeer(
|
|||||||
Port const& port,
|
Port const& port,
|
||||||
Handler& handler,
|
Handler& handler,
|
||||||
endpoint_type remote_address,
|
endpoint_type remote_address,
|
||||||
beast::http::request_v1<Body, Headers>&& request,
|
beast::http::request<Body, Headers>&& request,
|
||||||
socket_type&& socket,
|
socket_type&& socket,
|
||||||
beast::Journal journal)
|
beast::Journal journal)
|
||||||
: BaseWSPeer<Handler, PlainWSPeer>(port, handler, remote_address,
|
: BaseWSPeer<Handler, PlainWSPeer>(port, handler, remote_address,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
Port const& port,
|
Port const& port,
|
||||||
Handler& handler,
|
Handler& handler,
|
||||||
endpoint_type remote_endpoint,
|
endpoint_type remote_endpoint,
|
||||||
beast::http::request_v1<Body, Headers>&& request,
|
beast::http::request<Body, Headers>&& request,
|
||||||
std::unique_ptr<
|
std::unique_ptr<
|
||||||
beast::asio::ssl_bundle>&& ssl_bundle,
|
beast::asio::ssl_bundle>&& ssl_bundle,
|
||||||
beast::Journal journal);
|
beast::Journal journal);
|
||||||
@@ -76,7 +76,7 @@ SSLWSPeer(
|
|||||||
Port const& port,
|
Port const& port,
|
||||||
Handler& handler,
|
Handler& handler,
|
||||||
endpoint_type remote_endpoint,
|
endpoint_type remote_endpoint,
|
||||||
beast::http::request_v1<Body, Headers>&& request,
|
beast::http::request<Body, Headers>&& request,
|
||||||
std::unique_ptr<
|
std::unique_ptr<
|
||||||
beast::asio::ssl_bundle>&& ssl_bundle,
|
beast::asio::ssl_bundle>&& ssl_bundle,
|
||||||
beast::Journal journal)
|
beast::Journal journal)
|
||||||
|
|||||||
@@ -84,18 +84,18 @@ class ServerStatus_test :
|
|||||||
{
|
{
|
||||||
using namespace boost::asio;
|
using namespace boost::asio;
|
||||||
using namespace beast::http;
|
using namespace beast::http;
|
||||||
request_v1<string_body> req;
|
request<string_body> req;
|
||||||
|
|
||||||
req.url = "/";
|
req.url = "/";
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.headers.insert("Host", host + ":" + to_string(port));
|
req.fields.insert("Host", host + ":" + to_string(port));
|
||||||
req.headers.insert("User-Agent", "test");
|
req.fields.insert("User-Agent", "test");
|
||||||
req.method = "GET";
|
req.method = "GET";
|
||||||
req.headers.insert("Upgrade", "websocket");
|
req.fields.insert("Upgrade", "websocket");
|
||||||
beast::websocket::detail::maskgen maskgen;
|
beast::websocket::detail::maskgen maskgen;
|
||||||
std::string key = beast::websocket::detail::make_sec_ws_key(maskgen);
|
std::string key = beast::websocket::detail::make_sec_ws_key(maskgen);
|
||||||
req.headers.insert("Sec-WebSocket-Key", key);
|
req.fields.insert("Sec-WebSocket-Key", key);
|
||||||
req.headers.insert("Sec-WebSocket-Version", "13");
|
req.fields.insert("Sec-WebSocket-Version", "13");
|
||||||
prepare(req, connection::upgrade);
|
prepare(req, connection::upgrade);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
@@ -107,12 +107,12 @@ class ServerStatus_test :
|
|||||||
{
|
{
|
||||||
using namespace boost::asio;
|
using namespace boost::asio;
|
||||||
using namespace beast::http;
|
using namespace beast::http;
|
||||||
request_v1<string_body> req;
|
request<string_body> req;
|
||||||
|
|
||||||
req.url = "/";
|
req.url = "/";
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.headers.insert("Host", host + ":" + to_string(port));
|
req.fields.insert("Host", host + ":" + to_string(port));
|
||||||
req.headers.insert("User-Agent", "test");
|
req.fields.insert("User-Agent", "test");
|
||||||
if(body.empty())
|
if(body.empty())
|
||||||
{
|
{
|
||||||
req.method = "GET";
|
req.method = "GET";
|
||||||
@@ -120,7 +120,7 @@ class ServerStatus_test :
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
req.method = "POST";
|
req.method = "POST";
|
||||||
req.headers.insert("Content-Type", "application/json; charset=UTF-8");
|
req.fields.insert("Content-Type", "application/json; charset=UTF-8");
|
||||||
req.body = body;
|
req.body = body;
|
||||||
}
|
}
|
||||||
prepare(req);
|
prepare(req);
|
||||||
@@ -131,11 +131,11 @@ class ServerStatus_test :
|
|||||||
void
|
void
|
||||||
doRequest(
|
doRequest(
|
||||||
boost::asio::yield_context& yield,
|
boost::asio::yield_context& yield,
|
||||||
beast::http::request_v1<beast::http::string_body> const& req,
|
beast::http::request<beast::http::string_body> const& req,
|
||||||
std::string const& host,
|
std::string const& host,
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
bool secure,
|
bool secure,
|
||||||
beast::http::response_v1<beast::http::string_body>& resp,
|
beast::http::response<beast::http::string_body>& resp,
|
||||||
boost::system::error_code& ec)
|
boost::system::error_code& ec)
|
||||||
{
|
{
|
||||||
using namespace boost::asio;
|
using namespace boost::asio;
|
||||||
@@ -190,7 +190,7 @@ class ServerStatus_test :
|
|||||||
test::jtx::Env& env,
|
test::jtx::Env& env,
|
||||||
boost::asio::yield_context& yield,
|
boost::asio::yield_context& yield,
|
||||||
bool secure,
|
bool secure,
|
||||||
beast::http::response_v1<beast::http::string_body>& resp,
|
beast::http::response<beast::http::string_body>& resp,
|
||||||
boost::system::error_code& ec)
|
boost::system::error_code& ec)
|
||||||
{
|
{
|
||||||
auto const port = env.app().config()["port_ws"].
|
auto const port = env.app().config()["port_ws"].
|
||||||
@@ -207,7 +207,7 @@ class ServerStatus_test :
|
|||||||
test::jtx::Env& env,
|
test::jtx::Env& env,
|
||||||
boost::asio::yield_context& yield,
|
boost::asio::yield_context& yield,
|
||||||
bool secure,
|
bool secure,
|
||||||
beast::http::response_v1<beast::http::string_body>& resp,
|
beast::http::response<beast::http::string_body>& resp,
|
||||||
boost::system::error_code& ec,
|
boost::system::error_code& ec,
|
||||||
std::string const& body = "")
|
std::string const& body = "")
|
||||||
{
|
{
|
||||||
@@ -285,7 +285,7 @@ class ServerStatus_test :
|
|||||||
//non-secure request
|
//non-secure request
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
beast::http::response_v1<beast::http::string_body> resp;
|
beast::http::response<beast::http::string_body> resp;
|
||||||
doWSRequest(env, yield, false, resp, ec);
|
doWSRequest(env, yield, false, resp, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
return;
|
return;
|
||||||
@@ -295,7 +295,7 @@ class ServerStatus_test :
|
|||||||
//secure request
|
//secure request
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
beast::http::response_v1<beast::http::string_body> resp;
|
beast::http::response<beast::http::string_body> resp;
|
||||||
doWSRequest(env, yield, true, resp, ec);
|
doWSRequest(env, yield, true, resp, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
return;
|
return;
|
||||||
@@ -320,7 +320,7 @@ class ServerStatus_test :
|
|||||||
//non-secure request
|
//non-secure request
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
beast::http::response_v1<beast::http::string_body> resp;
|
beast::http::response<beast::http::string_body> resp;
|
||||||
doHTTPRequest(env, yield, false, resp, ec);
|
doHTTPRequest(env, yield, false, resp, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
return;
|
return;
|
||||||
@@ -330,7 +330,7 @@ class ServerStatus_test :
|
|||||||
//secure request
|
//secure request
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
beast::http::response_v1<beast::http::string_body> resp;
|
beast::http::response<beast::http::string_body> resp;
|
||||||
doHTTPRequest(env, yield, true, resp, ec);
|
doHTTPRequest(env, yield, true, resp, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
return;
|
return;
|
||||||
@@ -359,7 +359,7 @@ class ServerStatus_test :
|
|||||||
get<std::string>("ip");
|
get<std::string>("ip");
|
||||||
|
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
response_v1<string_body> resp;
|
response<string_body> resp;
|
||||||
auto req = makeWSUpgrade(*ip, *port);
|
auto req = makeWSUpgrade(*ip, *port);
|
||||||
|
|
||||||
//truncate the request message to near the value of the version header
|
//truncate the request message to near the value of the version header
|
||||||
@@ -400,7 +400,7 @@ class ServerStatus_test :
|
|||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env {*this, makeConfig(server_protocol)};
|
Env env {*this, makeConfig(server_protocol)};
|
||||||
|
|
||||||
beast::http::response_v1<beast::http::string_body> resp;
|
beast::http::response<beast::http::string_body> resp;
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
// The essence of this test is to have a client and server configured
|
// The essence of this test is to have a client and server configured
|
||||||
// out-of-phase with respect to ssl (secure client and insecure server
|
// out-of-phase with respect to ssl (secure client and insecure server
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include <ripple/json/to_string.h>
|
#include <ripple/json/to_string.h>
|
||||||
#include <ripple/protocol/JsonFields.h>
|
#include <ripple/protocol/JsonFields.h>
|
||||||
#include <ripple/server/Port.h>
|
#include <ripple/server/Port.h>
|
||||||
#include <beast/http/message_v1.hpp>
|
#include <beast/http/message.hpp>
|
||||||
#include <beast/http/streambuf_body.hpp>
|
#include <beast/http/streambuf_body.hpp>
|
||||||
#include <beast/http/string_body.hpp>
|
#include <beast/http/string_body.hpp>
|
||||||
#include <beast/http/read.hpp>
|
#include <beast/http/read.hpp>
|
||||||
@@ -108,12 +108,12 @@ public:
|
|||||||
using namespace boost::asio;
|
using namespace boost::asio;
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
request_v1<string_body> req;
|
request<string_body> req;
|
||||||
req.method = "POST";
|
req.method = "POST";
|
||||||
req.url = "/";
|
req.url = "/";
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.headers.insert("Content-Type", "application/json; charset=UTF-8");
|
req.fields.insert("Content-Type", "application/json; charset=UTF-8");
|
||||||
req.headers.insert("Host",
|
req.fields.insert("Host",
|
||||||
ep_.address().to_string() + ":" + std::to_string(ep_.port()));
|
ep_.address().to_string() + ":" + std::to_string(ep_.port()));
|
||||||
{
|
{
|
||||||
Json::Value jr;
|
Json::Value jr;
|
||||||
@@ -134,7 +134,7 @@ public:
|
|||||||
prepare(req);
|
prepare(req);
|
||||||
write(stream_, req);
|
write(stream_, req);
|
||||||
|
|
||||||
response_v1<streambuf_body> res;
|
response<streambuf_body> res;
|
||||||
read(stream_, bin_, res);
|
read(stream_, bin_, res);
|
||||||
|
|
||||||
Json::Reader jr;
|
Json::Reader jr;
|
||||||
|
|||||||
Reference in New Issue
Block a user