From 7f65fdc7f9a84fc340e0eb688cd912a5bdb2ca8b Mon Sep 17 00:00:00 2001
From: Seva <seva@binarytrails.net>
Date: Fri, 18 Oct 2019 00:50:35 -0400
Subject: [PATCH] http: try to read full content-length after headers

---
 src/http.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/http.cpp b/src/http.cpp
index 83b6c865..57127c89 100644
--- a/src/http.cpp
+++ b/src/http.cpp
@@ -917,8 +917,8 @@ Request::handle_response_header(const asio::error_code& ec)
     // has content-length
     if (content_length_it != response_.headers.end())
     {
-        std::getline(is, response_.body);
         unsigned int content_length = atoi(content_length_it->second.c_str());
+        response_.body.append(conn_->read_bytes(content_length));
         // full body already in the header
         if (response_.body.size() + 1 == content_length) {
             response_.body.append("\n");
@@ -985,9 +985,9 @@ Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
     // read the content-length body
     unsigned int content_length;
     if (content_length_it != response_.headers.end() and !response_.body.empty()){
-        response_.body.append(conn_->read_bytes(bytes));
         // extract the content-length
         content_length = atoi(content_length_it->second.c_str());
+        response_.body.append(conn_->read_bytes(bytes));
         // check if fully parsed
         if (response_.body.size() == content_length)
             parse_request(response_.body);
-- 
GitLab