mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-22 16:22:09 +00:00
feat: allow passing in a custom reqwest Client (#1745)
## Summary I am looking to instantiate a `RegistryClient`. However, when using the `RegistryClientBuilder` a new reqwest client is always constructed. I would like to pass in a custom `reqwest::Client` to be able to share the http resources with other parts of my application. ## Test Plan The uv codebase does not use my addition to the builder and all tests still succeed. And in my code I can pass a custom Client.
This commit is contained in:
parent
dd7d533411
commit
daf2800ddf
1 changed files with 18 additions and 10 deletions
|
@ -40,6 +40,7 @@ pub struct RegistryClientBuilder {
|
||||||
retries: u32,
|
retries: u32,
|
||||||
connectivity: Connectivity,
|
connectivity: Connectivity,
|
||||||
cache: Cache,
|
cache: Cache,
|
||||||
|
client: Option<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegistryClientBuilder {
|
impl RegistryClientBuilder {
|
||||||
|
@ -49,6 +50,7 @@ impl RegistryClientBuilder {
|
||||||
cache,
|
cache,
|
||||||
connectivity: Connectivity::Online,
|
connectivity: Connectivity::Online,
|
||||||
retries: 3,
|
retries: 3,
|
||||||
|
client: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,8 +80,14 @@ impl RegistryClientBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn client(mut self, client: Client) -> Self {
|
||||||
|
self.client = Some(client);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(self) -> RegistryClient {
|
pub fn build(self) -> RegistryClient {
|
||||||
let client_raw = {
|
let client_raw = self.client.unwrap_or_else(|| {
|
||||||
// Get pip timeout from env var
|
// Get pip timeout from env var
|
||||||
let default_timeout = 5 * 60;
|
let default_timeout = 5 * 60;
|
||||||
let timeout = env::var("UV_REQUEST_TIMEOUT")
|
let timeout = env::var("UV_REQUEST_TIMEOUT")
|
||||||
|
@ -99,7 +107,7 @@ impl RegistryClientBuilder {
|
||||||
.timeout(std::time::Duration::from_secs(timeout));
|
.timeout(std::time::Duration::from_secs(timeout));
|
||||||
|
|
||||||
client_core.build().expect("Failed to build HTTP client.")
|
client_core.build().expect("Failed to build HTTP client.")
|
||||||
};
|
});
|
||||||
|
|
||||||
let uncached_client = match self.connectivity {
|
let uncached_client = match self.connectivity {
|
||||||
Connectivity::Online => {
|
Connectivity::Online => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue