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
17 changes: 16 additions & 1 deletion crates/uv-client/src/base_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use itertools::Itertools;
use reqwest::{Client, ClientBuilder, Response};
use reqwest::{Client, ClientBuilder, Proxy, Response};
use reqwest_middleware::{ClientWithMiddleware, Middleware};
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::{
Expand Down Expand Up @@ -56,6 +56,7 @@ pub struct BaseClientBuilder<'a> {
url_auth_policies: Option<UrlAuthPolicies>,
default_timeout: Duration,
extra_middleware: Option<ExtraMiddleware>,
proxies: Vec<Proxy>,
}

/// A list of user-defined middlewares to be applied to the client.
Expand Down Expand Up @@ -90,6 +91,7 @@ impl BaseClientBuilder<'_> {
url_auth_policies: None,
default_timeout: Duration::from_secs(30),
extra_middleware: None,
proxies: vec![],
}
}
}
Expand Down Expand Up @@ -161,6 +163,12 @@ impl<'a> BaseClientBuilder<'a> {
self
}

#[must_use]
pub fn proxy(mut self, proxy: Proxy) -> Self {
self.proxies.push(proxy);
self
}

pub fn is_offline(&self) -> bool {
matches!(self.connectivity, Connectivity::Offline)
}
Expand Down Expand Up @@ -301,6 +309,13 @@ impl<'a> BaseClientBuilder<'a> {
client_builder
};

// apply proxies
let mut client_builder = client_builder;
for p in &self.proxies {
client_builder = client_builder.proxy(p.clone());
}
let client_builder = client_builder;

client_builder
.build()
.expect("Failed to build HTTP client.")
Expand Down
8 changes: 7 additions & 1 deletion crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use async_http_range_reader::AsyncHttpRangeReader;
use futures::{FutureExt, StreamExt, TryStreamExt};
use http::HeaderMap;
use itertools::Either;
use reqwest::{Response, StatusCode};
use reqwest::{Proxy, Response, StatusCode};
use reqwest_middleware::ClientWithMiddleware;
use tokio::sync::Semaphore;
use tracing::{info_span, instrument, trace, warn, Instrument};
Expand Down Expand Up @@ -133,6 +133,12 @@ impl<'a> RegistryClientBuilder<'a> {
self
}

#[must_use]
pub fn proxy(mut self, proxy: Proxy) -> Self {
self.base_client_builder = self.base_client_builder.proxy(proxy);
self
}

pub fn build(self) -> RegistryClient {
// Build a base client
let builder = self.base_client_builder;
Expand Down
Loading