From 93b1395daad0549c11dc01b66d3dc7c4da2f1a89 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 4 Mar 2024 19:18:49 -0800 Subject: [PATCH] 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. --- crates/uv-client/src/error.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/uv-client/src/error.rs b/crates/uv-client/src/error.rs index 19961286e..16830ee83 100644 --- a/crates/uv-client/src/error.rs +++ b/crates/uv-client/src/error.rs @@ -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; + } } }