DRY up HTTP request builder in source database (#2902)

This commit is contained in:
Charlie Marsh 2024-04-08 10:45:26 -04:00 committed by GitHub
parent f11a5e2208
commit 10dfd43af9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 27 deletions

View file

@ -356,18 +356,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
.boxed()
.instrument(info_span!("download", source_dist = %source))
};
let req = self
.client
.uncached_client()
.get(url.clone())
.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 req = self.request(url.clone())?;
let manifest = self
.client
.cached_client()
@ -460,18 +449,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
.boxed()
.instrument(info_span!("download", source_dist = %source))
};
let req = self
.client
.uncached_client()
.get(url.clone())
.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 req = self.request(url.clone())?;
let manifest = self
.client
.cached_client()
@ -1103,6 +1081,21 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
debug!("Finished building (editable): {dist}");
Ok((dist, disk_filename, filename, metadata))
}
/// 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()
}
}
#[derive(Debug)]