From 755be66329823dde3985bb25ecf4674fc003255f Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Tue, 9 Dec 2025 19:11:59 +0100 Subject: fix reading of stale iterator when doing download-resume (#681) --- src/zenhttp/clients/httpclientcpr.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') 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(It->second); ParsedContentLength.has_value()) + { + ContentLength = ParsedContentLength.value(); + } + } + std::vector> 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(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()) { -- cgit v1.2.3