Skip to content

Commit

Permalink
Turn off default proxy detection
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Sep 30, 2023
1 parent a591c8d commit a3bf7f0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum RedirectAuthHeaders {
/// Accumulates options towards building an [Agent].
pub struct AgentBuilder {
config: AgentConfig,
no_proxy: bool,
try_proxy_from_env: bool,
max_idle_connections: usize,
max_idle_connections_per_host: usize,
/// Cookies saved between requests.
Expand Down Expand Up @@ -264,7 +264,7 @@ impl AgentBuilder {
user_agent: format!("ureq/{}", env!("CARGO_PKG_VERSION")),
tls_config: TlsConfig(crate::default_tls_config()),
},
no_proxy: false,
try_proxy_from_env: false,
max_idle_connections: DEFAULT_MAX_IDLE_CONNECTIONS,
max_idle_connections_per_host: DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST,
resolver: StdResolver.into(),
Expand All @@ -280,7 +280,7 @@ impl AgentBuilder {
// not implement clone, so we have to give ownership to the newly
// built Agent.
pub fn build(mut self) -> Agent {
if self.config.proxy.is_none() && !self.no_proxy {
if self.config.proxy.is_none() && self.try_proxy_from_env {
if let Some(proxy) = Proxy::try_from_system() {
self.config.proxy = Some(proxy);
}
Expand Down Expand Up @@ -314,16 +314,20 @@ impl AgentBuilder {
/// # }
/// ```
///
/// # Note
/// Adding a proxy will disable the automatic usage of the “system” proxy.
/// Adding a proxy will disable `try_proxy_from_env`.
pub fn proxy(mut self, proxy: Proxy) -> Self {
self.config.proxy = Some(proxy);
self
}

/// Don't auto detect proxy from system environment, e.g. HTTP_PROXY
pub fn no_proxy(mut self) -> Self {
self.no_proxy = true;
/// Attempt to detect proxy settings from the environment, i.e. HTTP_PROXY
///
/// The default is `false`, i.e. not detecting proxy from env since this is
/// a potential security risk.
///
/// If the `proxy` is set on the builder, this setting has no effect.
pub fn try_proxy_from_env(mut self, do_try: bool) -> Self {
self.try_proxy_from_env = do_try;
self
}

Expand Down

0 comments on commit a3bf7f0

Please sign in to comment.