Fallback to non-range requests when HEAD returns 404 (#2186)

## Summary

We have at least one reported case of this happening. It's preferable
IMO to move on rather than fail hard despite sub-pbar registry behavior.

Closes https://github.com/astral-sh/uv/issues/2099.
This commit is contained in:
Charlie Marsh 2024-03-04 19:18:49 -08:00 committed by GitHub
parent 60a78812f9
commit 93b1395daa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -170,9 +170,18 @@ impl ErrorKind {
// HEAD requests, so we can't check for range requests.
Self::ReqwestError(err) => {
if let Some(status) = err.status() {
// If the server doesn't support HEAD requests, we can't check for range
// requests.
if status == reqwest::StatusCode::METHOD_NOT_ALLOWED {
return true;
}
// In some cases, registries return a 404 for HEAD requests when they're not
// supported. In the worst case, we'll now just proceed to attempt to stream the
// entire file, so it's fine to be somewhat lenient here.
if status == reqwest::StatusCode::NOT_FOUND {
return true;
}
}
}