libstore: use effective transfer url for retries
do not retread the entire redirection path if we've seen the end of the
road. this avoids silently downloading wrong data, and notifies us when
a url we've received data from turns into a redirect when retrying. for
reasons of simplicity we don't turn of libcurl redirects on retries. if
we did that we'd have to conditionally process http status codes, which
sounds annoying and would make the header callback even more of a mess.
Change-Id: Ide0c0512ef9b2579350101246d654a2375541a39
This commit is contained in:
parent
2b3bdda027
commit
7c716b9716
|
@ -167,8 +167,19 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
char * effectiveUriCStr = nullptr;
|
char * effectiveUriCStr = nullptr;
|
||||||
curl_easy_getinfo(req, CURLINFO_EFFECTIVE_URL, &effectiveUriCStr);
|
curl_easy_getinfo(req, CURLINFO_EFFECTIVE_URL, &effectiveUriCStr);
|
||||||
if (effectiveUriCStr)
|
if (effectiveUriCStr) {
|
||||||
|
if (!result.effectiveUri.empty() && result.effectiveUri != effectiveUriCStr) {
|
||||||
|
throw FileTransferError(
|
||||||
|
Misc,
|
||||||
|
{},
|
||||||
|
"uri %s changed final destination from %s to %s during transfer",
|
||||||
|
uri,
|
||||||
|
result.effectiveUri,
|
||||||
|
effectiveUriCStr
|
||||||
|
);
|
||||||
|
}
|
||||||
result.effectiveUri = effectiveUriCStr;
|
result.effectiveUri = effectiveUriCStr;
|
||||||
|
}
|
||||||
|
|
||||||
result.cached = getHTTPStatus() == 304;
|
result.cached = getHTTPStatus() == 304;
|
||||||
|
|
||||||
|
@ -307,6 +318,10 @@ struct curlFileTransfer : public FileTransfer
|
||||||
curl_easy_setopt(req, CURLOPT_DEBUGFUNCTION, TransferItem::debugCallback);
|
curl_easy_setopt(req, CURLOPT_DEBUGFUNCTION, TransferItem::debugCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use the effective URI of the previous transfer for retries. this avoids
|
||||||
|
// some silent corruption if a redirect changes between starting and retry.
|
||||||
|
const auto & uri = result.effectiveUri.empty() ? this->uri : result.effectiveUri;
|
||||||
|
|
||||||
curl_easy_setopt(req, CURLOPT_URL, uri.c_str());
|
curl_easy_setopt(req, CURLOPT_URL, uri.c_str());
|
||||||
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
curl_easy_setopt(req, CURLOPT_MAXREDIRS, 10);
|
curl_easy_setopt(req, CURLOPT_MAXREDIRS, 10);
|
||||||
|
|
Loading…
Reference in a new issue