diff --git a/crates/uv-client/src/registry_client.rs b/crates/uv-client/src/registry_client.rs index cf2b23771298..389e26ea8096 100644 --- a/crates/uv-client/src/registry_client.rs +++ b/crates/uv-client/src/registry_client.rs @@ -6,7 +6,7 @@ use std::str::FromStr; use async_http_range_reader::AsyncHttpRangeReader; use futures::{FutureExt, TryStreamExt}; use http::HeaderMap; -use reqwest::{Client, Response, StatusCode}; +use reqwest::{Client, Response, ResponseBuilderExt, StatusCode}; use serde::{Deserialize, Serialize}; use tokio::io::AsyncReadExt; use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; @@ -520,7 +520,7 @@ impl RegistryClient { async { let mut reader = AsyncHttpRangeReader::from_head_response( self.uncached_client().client(), - response, + response_with_original_url(response, url.clone()), headers, ) .await @@ -612,6 +612,18 @@ impl RegistryClient { } } +fn response_with_original_url(response: Response, original_url: Url) -> Response { + let mut r = http::Response::builder() + .status(response.status()) + .url(original_url) + .version(response.version()); + for (name, value) in response.headers() { + r = r.header(name, value); + } + let r = r.body("").unwrap(); + Response::from(r) +} + /// Read a wheel's `METADATA` file from a zip file. async fn read_metadata_async_seek( filename: &WheelFilename,