mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-30 14:01:13 +00:00
DRY up request builer in wheel download (#2857)
This commit is contained in:
parent
a3de0e8bc6
commit
d4a258422b
1 changed files with 17 additions and 26 deletions
|
@ -413,18 +413,6 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
||||||
.instrument(info_span!("wheel", wheel = %dist))
|
.instrument(info_span!("wheel", wheel = %dist))
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = self
|
|
||||||
.client
|
|
||||||
.uncached_client()
|
|
||||||
.get(url)
|
|
||||||
.header(
|
|
||||||
// `reqwest` defaults to accepting compressed responses.
|
|
||||||
// Specify identity encoding to get consistent .whl downloading
|
|
||||||
// behavior from servers. ref: https://github.com/pypa/pip/pull/1688
|
|
||||||
"accept-encoding",
|
|
||||||
reqwest::header::HeaderValue::from_static("identity"),
|
|
||||||
)
|
|
||||||
.build()?;
|
|
||||||
let cache_control = match self.client.connectivity() {
|
let cache_control = match self.client.connectivity() {
|
||||||
Connectivity::Online => CacheControl::from(
|
Connectivity::Online => CacheControl::from(
|
||||||
self.build_context
|
self.build_context
|
||||||
|
@ -438,7 +426,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
||||||
let archive = self
|
let archive = self
|
||||||
.client
|
.client
|
||||||
.cached_client()
|
.cached_client()
|
||||||
.get_serde(req, &http_entry, cache_control, download)
|
.get_serde(self.request(url)?, &http_entry, cache_control, download)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
CachedClientError::Callback(err) => err,
|
CachedClientError::Callback(err) => err,
|
||||||
|
@ -495,18 +483,6 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
||||||
.instrument(info_span!("wheel", wheel = %dist))
|
.instrument(info_span!("wheel", wheel = %dist))
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = self
|
|
||||||
.client
|
|
||||||
.uncached_client()
|
|
||||||
.get(url)
|
|
||||||
.header(
|
|
||||||
// `reqwest` defaults to accepting compressed responses.
|
|
||||||
// Specify identity encoding to get consistent .whl downloading
|
|
||||||
// behavior from servers. ref: https://github.com/pypa/pip/pull/1688
|
|
||||||
"accept-encoding",
|
|
||||||
reqwest::header::HeaderValue::from_static("identity"),
|
|
||||||
)
|
|
||||||
.build()?;
|
|
||||||
let cache_control = match self.client.connectivity() {
|
let cache_control = match self.client.connectivity() {
|
||||||
Connectivity::Online => CacheControl::from(
|
Connectivity::Online => CacheControl::from(
|
||||||
self.build_context
|
self.build_context
|
||||||
|
@ -520,7 +496,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
||||||
let archive = self
|
let archive = self
|
||||||
.client
|
.client
|
||||||
.cached_client()
|
.cached_client()
|
||||||
.get_serde(req, &http_entry, cache_control, download)
|
.get_serde(self.request(url)?, &http_entry, cache_control, download)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
CachedClientError::Callback(err) => err,
|
CachedClientError::Callback(err) => err,
|
||||||
|
@ -530,6 +506,21 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
||||||
Ok(archive)
|
Ok(archive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a GET [`reqwest::Request`] for the given URL.
|
||||||
|
fn request(&self, url: Url) -> Result<reqwest::Request, reqwest::Error> {
|
||||||
|
self.client
|
||||||
|
.uncached_client()
|
||||||
|
.get(url)
|
||||||
|
.header(
|
||||||
|
// `reqwest` defaults to accepting compressed responses.
|
||||||
|
// Specify identity encoding to get consistent .whl downloading
|
||||||
|
// behavior from servers. ref: https://github.com/pypa/pip/pull/1688
|
||||||
|
"accept-encoding",
|
||||||
|
reqwest::header::HeaderValue::from_static("identity"),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the [`IndexLocations`] used by this resolver.
|
/// Return the [`IndexLocations`] used by this resolver.
|
||||||
pub fn index_locations(&self) -> &IndexLocations {
|
pub fn index_locations(&self) -> &IndexLocations {
|
||||||
self.build_context.index_locations()
|
self.build_context.index_locations()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue