diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/zenhttp/clients/httpclientcpr.cpp | 18 |
2 files changed, 10 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ca82d771c..de5242692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Improvement: Stop unhandled exceptions from async work in windows threadpool - Improvement: Upload of data to zen cache during oplog import is now disabled by default - Bugfix: Fixed warning due to calling std::filesystem::equivalent on a non-existing path +- Bugfix: Resume download in http client no longer tries to read from a stale header iterator ## 5.7.13 - Feature: Added `--append` option to `zen builds download` diff --git a/src/zenhttp/clients/httpclientcpr.cpp b/src/zenhttp/clients/httpclientcpr.cpp index 7bfc4670c..987cdd706 100644 --- a/src/zenhttp/clients/httpclientcpr.cpp +++ b/src/zenhttp/clients/httpclientcpr.cpp @@ -1038,6 +1038,15 @@ CprHttpClient::Download(std::string_view Url, const std::filesystem::path& TempF auto It = Response.header.find("Content-Length"); if (It != Response.header.end()) { + uint64_t ContentLength = RequestedContentLength; + if (ContentLength == uint64_t(-1)) + { + if (auto ParsedContentLength = ParseInt<int64_t>(It->second); ParsedContentLength.has_value()) + { + ContentLength = ParsedContentLength.value(); + } + } + std::vector<std::pair<std::string, std::string>> ReceivedHeaders; auto HeaderCallback = [&](std::string header, intptr_t) { @@ -1088,15 +1097,6 @@ CprHttpClient::Download(std::string_view Url, const std::filesystem::path& TempF { uint64_t DownloadedSize = PayloadFile ? PayloadFile->GetSize() : PayloadString.length(); - uint64_t ContentLength = RequestedContentLength; - if (ContentLength == uint64_t(-1)) - { - if (auto ParsedContentLength = ParseInt<int64_t>(It->second); ParsedContentLength.has_value()) - { - ContentLength = ParsedContentLength.value(); - } - } - std::string Range = fmt::format("bytes={}-{}", DownloadedSize, DownloadedSize + ContentLength - 1); if (auto RangeIt = HeadersWithRange.Entries.find("Range"); RangeIt != HeadersWithRange.Entries.end()) { |