Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async-compression = { version = "0.4.12", features = [
"zstd",
] }
async-trait = { version = "0.1.82" }
async_http_range_reader = { version = "0.10.0", package = "astral_async_http_range_reader" }
async_http_range_reader = { version = "0.11.0", package = "astral_async_http_range_reader" }
async_zip = { version = "0.0.17", package = "astral_async_zip", features = [
"bzip2",
"deflate",
Expand Down
60 changes: 50 additions & 10 deletions crates/uv-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use reqwest::Response;
use serde::Deserialize;
use tracing::warn;

use crate::middleware::OfflineError;
use crate::{FlatIndexError, html};
use uv_cache::Error as CacheError;
use uv_distribution_filename::{WheelFilename, WheelFilenameError};
use uv_distribution_types::IndexUrl;
use uv_normalize::PackageName;
use uv_redacted::DisplaySafeUrl;

use crate::middleware::OfflineError;
use crate::{FlatIndexError, html};

/// RFC 9457 Problem Details for HTTP APIs
///
/// This structure represents the standard format for machine-readable details
Expand Down Expand Up @@ -242,7 +242,11 @@ impl Error {
}

/// Returns `true` if the error is due to the server not supporting HTTP range requests.
pub fn is_http_range_requests_unsupported(&self) -> bool {
pub fn is_http_range_requests_unsupported(
&self,
url: &DisplaySafeUrl,
index: Option<&IndexUrl>,
) -> bool {
match &*self.kind {
// The server doesn't support range requests (as reported by the `HEAD` check).
ErrorKind::AsyncHttpRangeReader(
Expand All @@ -261,6 +265,25 @@ impl Error {
return true;
}

// The server advertises range request support, but doesn't implement it correctly.
ErrorKind::AsyncHttpRangeReader(
_,
AsyncHttpRangeReaderError::RangeMismatch { .. }
| AsyncHttpRangeReaderError::ResponseTooShort { .. }
| AsyncHttpRangeReaderError::ResponseTooLong { .. },
) => {
let url = if let Some(index) = index {
index.url()
} else {
url
};
warn!(
"Invalid range request response from server that declares HTTP range request \
support, falling back to streaming: {url}"
);
return true;
}

// The server returned a "Method Not Allowed" error, indicating it doesn't support
// HEAD requests, so we can't check for range requests.
ErrorKind::WrappedReqwestError(_, err) => {
Expand Down Expand Up @@ -295,14 +318,31 @@ impl Error {
// The server doesn't support range requests, but we only discovered this while
// unzipping due to erroneous server behavior.
ErrorKind::Zip(_, ZipError::UpstreamReadError(err)) => {
if let Some(inner) = err.get_ref() {
if let Some(inner) = inner.downcast_ref::<AsyncHttpRangeReaderError>() {
if matches!(
inner,
AsyncHttpRangeReaderError::HttpRangeRequestUnsupported
) {
if let Some(inner) = err.get_ref()
&& let Some(range_reader_error) =
inner.downcast_ref::<AsyncHttpRangeReaderError>()
{
match range_reader_error {
AsyncHttpRangeReaderError::HttpRangeRequestUnsupported
| AsyncHttpRangeReaderError::ContentLengthMissing
| AsyncHttpRangeReaderError::ContentRangeMissing => {
return true;
}
AsyncHttpRangeReaderError::RangeMismatch { .. }
| AsyncHttpRangeReaderError::ResponseTooShort { .. }
| AsyncHttpRangeReaderError::ResponseTooLong { .. } => {
let url = if let Some(index) = index {
index.url()
} else {
url
};
warn!(
"Invalid range request response from server that declares HTTP \
range request support, falling back to streaming: {url}"
);
return true;
}
_ => {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ impl RegistryClient {
match result {
Ok(metadata) => return Ok(metadata),
Err(err) => {
if err.is_http_range_requests_unsupported() {
if err.is_http_range_requests_unsupported(url, index) {
// The range request version failed. Fall back to streaming the file to search
// for the METADATA file.
warn!("Range requests not supported for {filename}; streaming wheel");
Expand Down
Loading