aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/httpclient.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-01-24 15:56:14 +0100
committerGitHub <[email protected]>2024-01-24 15:56:14 +0100
commit928a757cb982062c9cebcc2d7a445cdf7ac807e7 (patch)
tree0e4c2d6e480d8987d2ce16135997bf47dd0cd7cc /src/zenhttp/httpclient.cpp
parent0.2.39-pre1 (diff)
downloadzen-928a757cb982062c9cebcc2d7a445cdf7ac807e7.tar.xz
zen-928a757cb982062c9cebcc2d7a445cdf7ac807e7.zip
Use proper format for range request header (#640)
Clear header callback after use Use separate temp-vector for headers
Diffstat (limited to 'src/zenhttp/httpclient.cpp')
-rw-r--r--src/zenhttp/httpclient.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp
index 3b2a3baec..8182ac68f 100644
--- a/src/zenhttp/httpclient.cpp
+++ b/src/zenhttp/httpclient.cpp
@@ -198,6 +198,7 @@ struct HttpClient::Impl : public RefCounted
}
cpr::Response Result = CprSession->Download(Write);
ZEN_TRACE("GET {}", Result);
+ CprSession->SetHeaderCallback({});
return Result;
}
inline cpr::Response Head()
@@ -872,7 +873,6 @@ HttpClient::Download(std::string_view Url, const std::filesystem::path& TempFold
m_Impl->AllocSession(m_BaseUri, Url, m_ConnectionSettings, AdditionalHeader, {}, m_SessionId, GetAccessToken());
Response = Sess.Download(cpr::WriteCallback{DownloadCallback});
}
-
if (m_ConnectionSettings.AllowResume)
{
auto SupportsRanges = [](const cpr::Response& Response) -> bool {
@@ -903,6 +903,8 @@ HttpClient::Download(std::string_view Url, const std::filesystem::path& TempFold
std::optional<int64_t> ContentLength = ParseInt<int64_t>(It->second);
if (ContentLength)
{
+ std::vector<std::pair<std::string, std::string>> ReceivedHeaders;
+
auto HeaderCallback = [&](std::string header, intptr_t) {
size_t DelimiterPos = header.find(':');
if (DelimiterPos != std::string::npos)
@@ -916,7 +918,7 @@ HttpClient::Download(std::string_view Url, const std::filesystem::path& TempFold
Value = AsciiSet::TrimSuffixWith(Value, WhitespaceCharacters);
Value = AsciiSet::TrimPrefixWith(Value, WhitespaceCharacters);
- Response.header.insert_or_assign(Key, Value);
+ ReceivedHeaders.push_back({Key, Value});
if (Key == "Content-Range"sv)
{
@@ -960,7 +962,7 @@ HttpClient::Download(std::string_view Url, const std::filesystem::path& TempFold
{
uint64_t DownloadedSize = PayloadFile ? PayloadFile->GetSize() : PayloadString.length();
- std::string Range = fmt::format("{}-{}", DownloadedSize, ContentLength.value());
+ std::string Range = fmt::format("bytes={}-{}", DownloadedSize, ContentLength.value());
if (auto RangeIt = HeadersWithRange.Entries.find("Range"); RangeIt != HeadersWithRange.Entries.end())
{
if (RangeIt->second == Range)
@@ -978,8 +980,12 @@ HttpClient::Download(std::string_view Url, const std::filesystem::path& TempFold
{},
m_SessionId,
GetAccessToken());
- Response.header.clear();
Response = Sess.Download(cpr::WriteCallback{DownloadCallback}, cpr::HeaderCallback{HeaderCallback});
+ for (const std::pair<std::string, std::string>& H : ReceivedHeaders)
+ {
+ Response.header.insert_or_assign(H.first, H.second);
+ }
+ ReceivedHeaders.clear();
} while (ShouldResume(Response));
}
}