From e52614ac815870526e484909046236f6f7a95ad7 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 20 Dec 2016 02:26:23 -0800 Subject: [PATCH] HTTPClient should support large replies (RIPD-1366): A full ledger on the production Ripple network could exceed the default maximum reply size for the HTTPClient code. Remove the reply size maximum for responses that include a Content-Length header. --- src/ripple/net/HTTPClient.h | 6 +++--- src/ripple/net/impl/HTTPClient.cpp | 21 ++++++++------------- src/ripple/net/impl/RPCCall.cpp | 3 +++ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ripple/net/HTTPClient.h b/src/ripple/net/HTTPClient.h index 634397eb77..63473be756 100644 --- a/src/ripple/net/HTTPClient.h +++ b/src/ripple/net/HTTPClient.h @@ -45,7 +45,7 @@ public: std::deque deqSites, const unsigned short port, std::string const& strPath, - std::size_t responseMax, + std::size_t responseMax, // if no Content-Length header std::chrono::seconds timeout, std::function complete, beast::Journal& j); @@ -56,7 +56,7 @@ public: std::string strSite, const unsigned short port, std::string const& strPath, - std::size_t responseMax, + std::size_t responseMax, // if no Content-Length header std::chrono::seconds timeout, std::function complete, beast::Journal& j); @@ -67,7 +67,7 @@ public: std::string strSite, const unsigned short port, std::function build, - std::size_t responseMax, + std::size_t responseMax, // if no Content-Length header std::chrono::seconds timeout, std::function complete, beast::Journal& j); diff --git a/src/ripple/net/impl/HTTPClient.cpp b/src/ripple/net/impl/HTTPClient.cpp index dcad22e958..61fb76dbb6 100644 --- a/src/ripple/net/impl/HTTPClient.cpp +++ b/src/ripple/net/impl/HTTPClient.cpp @@ -104,13 +104,13 @@ class HTTPClientImp public: HTTPClientImp (boost::asio::io_service& io_service, const unsigned short port, - std::size_t responseMax, + std::size_t responseSize, beast::Journal& j) : mSocket (io_service, httpClientSSLContext->context ()) , mResolver (io_service) , mHeader (maxClientHeaderBytes) , mPort (port) - , mResponseMax (responseMax) + , mResponseSize (responseSize) , mDeadline (io_service) , j_ (j) { @@ -411,19 +411,14 @@ public: mBody = smMatch[1]; if (boost::regex_match (strHeader, smMatch, reSize)) - { - int size = beast::lexicalCastThrow (std::string(smMatch[1])); + mResponseSize = beast::lexicalCastThrow (std::string(smMatch[1])); - if (size < mResponseMax) - mResponseMax = size; - } - - if (mResponseMax == 0) + if (mResponseSize == 0) { // no body wanted or available invokeComplete (ecResult, mStatus); } - else if (mBody.size () >= mResponseMax) + else if (mBody.size () >= mResponseSize) { // we got the whole thing invokeComplete (ecResult, mStatus, mBody); @@ -431,7 +426,7 @@ public: else { mSocket.async_read ( - mResponse.prepare (mResponseMax - mBody.size ()), + mResponse.prepare (mResponseSize - mBody.size ()), boost::asio::transfer_all (), std::bind (&HTTPClientImp::handleData, shared_from_this (), @@ -507,13 +502,13 @@ private: bool mSSL; AutoSocket mSocket; boost::asio::ip::tcp::resolver mResolver; - std::shared_ptr mQuery; + std::shared_ptr mQuery; boost::asio::streambuf mRequest; boost::asio::streambuf mHeader; boost::asio::streambuf mResponse; std::string mBody; const unsigned short mPort; - int mResponseMax; + int mResponseSize; int mStatus; std::function mBuild; std::function mComplete; diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 05a177808a..7ae7596310 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -1415,7 +1415,10 @@ void fromNetwork ( // Send request + // Number of bytes to try to receive if no + // Content-Length header received const int RPC_REPLY_MAX_BYTES (256*1024*1024); + using namespace std::chrono_literals; auto constexpr RPC_NOTIFY = 10min;