mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Beast.HTTP:
New classes are introduced to represent HTTP messages and their associated bodies. The parser interface is reworked to use CRTP, error codes, and trait checks. New classes: * basic_headers Models field/value pairs in a HTTP message. * message Models a HTTP message, body behavior defined by template argument. Parsed message carries metadata generated during parsing. * parser Produces parsed messages. * empty_body, string_body, basic_streambuf_body Classes used to represent content bodies in various ways. New functions: * read, async_read, write, async_write Read and write HTTP messages on a socket. New concepts: * Body: Represents the HTTP Content-Body. * Field: A HTTP header field. * FieldSequence: A forward sequence of fields. * Reader: Parses a Body from a stream of bytes. * Writer: Serializes a Body to buffers. basic_parser changes: * add write methods which throw exceptions instead * error_code passed via parameter instead of return value * fold private member calls into existing callbacks * basic_parser uses CRTP instead of virtual members * add documentation on Derived requirements for CRTP impl/http-parser changes: * joyent renamed to nodejs to reflect upstream changes
This commit is contained in:
@@ -218,7 +218,7 @@ ConnectAttempt::onHandshake (error_code ec)
|
||||
if (! sharedValue)
|
||||
return close(); // makeSharedValue logs
|
||||
|
||||
beast::http::message req = makeRequest(
|
||||
beast::deprecated_http::message req = makeRequest(
|
||||
! overlay_.peerFinder().config().peerPrivate,
|
||||
remote_endpoint_.address());
|
||||
auto const hello = buildHello (
|
||||
@@ -226,10 +226,9 @@ ConnectAttempt::onHandshake (error_code ec)
|
||||
overlay_.setup().public_ip,
|
||||
beast::IPAddressConversion::from_asio(remote_endpoint_),
|
||||
app_);
|
||||
appendHello (req, hello);
|
||||
appendHello (req.headers, hello);
|
||||
|
||||
using beast::http::write;
|
||||
write (write_buf_, req);
|
||||
beast::deprecated_http::write (write_buf_, req);
|
||||
|
||||
setTimer();
|
||||
stream_.async_write_some (write_buf_.data(),
|
||||
@@ -293,10 +292,9 @@ ConnectAttempt::onRead (error_code ec, std::size_t bytes_transferred)
|
||||
|
||||
if (! ec)
|
||||
{
|
||||
write_buf_.commit (bytes_transferred);
|
||||
std::size_t bytes_consumed;
|
||||
std::tie (ec, bytes_consumed) = parser_.write(
|
||||
write_buf_.data());
|
||||
write_buf_.commit(bytes_transferred);
|
||||
auto bytes_consumed = parser_.write(
|
||||
write_buf_.data(), ec);
|
||||
if (! ec)
|
||||
{
|
||||
write_buf_.consume (bytes_consumed);
|
||||
@@ -332,26 +330,26 @@ ConnectAttempt::onShutdown (error_code ec)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
beast::http::message
|
||||
beast::deprecated_http::message
|
||||
ConnectAttempt::makeRequest (bool crawl,
|
||||
boost::asio::ip::address const& remote_address)
|
||||
{
|
||||
beast::http::message m;
|
||||
beast::deprecated_http::message m;
|
||||
m.method (beast::http::method_t::http_get);
|
||||
m.url ("/");
|
||||
m.version (1, 1);
|
||||
m.headers.append ("User-Agent", BuildInfo::getFullVersionString());
|
||||
m.headers.append ("Upgrade", "RTXP/1.2");
|
||||
m.headers.insert ("User-Agent", BuildInfo::getFullVersionString());
|
||||
m.headers.insert ("Upgrade", "RTXP/1.2");
|
||||
//std::string("RTXP/") + to_string (BuildInfo::getCurrentProtocol()));
|
||||
m.headers.append ("Connection", "Upgrade");
|
||||
m.headers.append ("Connect-As", "Peer");
|
||||
m.headers.append ("Crawl", crawl ? "public" : "private");
|
||||
m.headers.insert ("Connection", "Upgrade");
|
||||
m.headers.insert ("Connect-As", "Peer");
|
||||
m.headers.insert ("Crawl", crawl ? "public" : "private");
|
||||
return m;
|
||||
}
|
||||
|
||||
template <class Streambuf>
|
||||
void
|
||||
ConnectAttempt::processResponse (beast::http::message const& m,
|
||||
ConnectAttempt::processResponse (beast::deprecated_http::message const& m,
|
||||
Streambuf const& body)
|
||||
{
|
||||
if (response_.status() == 503)
|
||||
@@ -392,7 +390,7 @@ ConnectAttempt::processResponse (beast::http::message const& m,
|
||||
return close();
|
||||
}
|
||||
|
||||
auto hello = parseHello (response_, journal_);
|
||||
auto hello = parseHello (false, response_.headers, journal_);
|
||||
if(! hello)
|
||||
return fail("processResponse: Bad TMHello");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user