From 4361a4331f1b2eb3fcfd954c96de353c9d516508 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Aug 2018 11:31:14 +0200 Subject: [PATCH] Fix reporting of HTTP body size when a result callback is used --- src/libstore/download.cc | 5 ++++- src/libstore/download.hh | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libstore/download.cc b/src/libstore/download.cc index f80c9e45b..f0ea1995a 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>(line, " "); status = ss.size() >= 2 ? ss[1] : ""; result.data = std::make_shared(); + 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(); + 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 da55df7a6..ff38a2870 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 data; + uint64_t bodySize = 0; }; class Store;