about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-08-06T09·31+0200
committerEelco Dolstra <edolstra@gmail.com>2018-08-06T09·31+0200
commit4361a4331f1b2eb3fcfd954c96de353c9d516508 (patch)
tree100fdd9da05e6211645f72672cd6830f1a198c68
parent2825e05d21ecabc8b8524836baf0b9b05da993c6 (diff)
Fix reporting of HTTP body size when a result callback is used
-rw-r--r--src/libstore/download.cc5
-rw-r--r--src/libstore/download.hh1
2 files changed, 5 insertions, 1 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index f80c9e45b82e..f0ea1995ae73 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -140,6 +140,7 @@ struct CurlDownloader : public Downloader
         size_t writeCallback(void * contents, size_t size, size_t nmemb)
         {
             size_t realSize = size * nmemb;
+            result.bodySize += realSize;
             if (request.dataCallback)
                 request.dataCallback((char *) contents, realSize);
             else
@@ -162,6 +163,7 @@ struct CurlDownloader : public Downloader
                 auto ss = tokenizeString<vector<string>>(line, " ");
                 status = ss.size() >= 2 ? ss[1] : "";
                 result.data = std::make_shared<std::string>();
+                result.bodySize = 0;
                 encoding = "";
             } else {
                 auto i = line.find(':');
@@ -296,6 +298,7 @@ struct CurlDownloader : public Downloader
             curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 
             result.data = std::make_shared<std::string>();
+            result.bodySize = 0;
         }
 
         void finish(CURLcode code)
@@ -309,7 +312,7 @@ struct CurlDownloader : public Downloader
                 result.effectiveUrl = effectiveUrlCStr;
 
             debug("finished %s of '%s'; curl status = %d, HTTP status = %d, body = %d bytes",
-                request.verb(), request.uri, code, httpStatus, result.data ? result.data->size() : 0);
+                request.verb(), request.uri, code, httpStatus, result.bodySize);
 
             if (code == CURLE_WRITE_ERROR && result.etag == request.expectedETag) {
                 code = CURLE_OK;
diff --git a/src/libstore/download.hh b/src/libstore/download.hh
index da55df7a6e71..ff38a2870cc0 100644
--- a/src/libstore/download.hh
+++ b/src/libstore/download.hh
@@ -38,6 +38,7 @@ struct DownloadResult
     std::string etag;
     std::string effectiveUrl;
     std::shared_ptr<std::string> data;
+    uint64_t bodySize = 0;
 };
 
 class Store;