From 3d3a4c978d1f72b2a53de2ae189767a5aabbd069 Mon Sep 17 00:00:00 2001 From: SPQV MF Date: Wed, 22 Nov 2023 03:11:05 +0800 Subject: [PATCH 1/2] feat: add a feature flag "proxy-from-env" to control whether or not to detect proxy settings from environment by default --- Cargo.toml | 1 + src/agent.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 0050cdcb..fc602848 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ socks-proxy = ["dep:socks"] gzip = ["dep:flate2"] brotli = ["dep:brotli-decompressor"] http-interop = ["dep:http"] +proxy-from-env = [] [dependencies] base64 = "0.21" diff --git a/src/agent.rs b/src/agent.rs index c4495d71..a114eaad 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -264,6 +264,9 @@ impl AgentBuilder { user_agent: format!("ureq/{}", env!("CARGO_PKG_VERSION")), tls_config: TlsConfig(crate::default_tls_config()), }, + #[cfg(feature = "proxy-from-env")] + try_proxy_from_env: true, + #[cfg(not(feature = "proxy-from-env"))] try_proxy_from_env: false, max_idle_connections: DEFAULT_MAX_IDLE_CONNECTIONS, max_idle_connections_per_host: DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST, From d9bbb4549997a73a3d156ff2a86af7e525ab4069 Mon Sep 17 00:00:00 2001 From: SPQV MF Date: Wed, 22 Nov 2023 03:16:45 +0800 Subject: [PATCH 2/2] docs: update doc comment on `try_proxy_from_env` method to reflect the `proxy-from-env` feature flag --- src/agent.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index a114eaad..30a0038e 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -325,8 +325,9 @@ impl AgentBuilder { /// 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. + /// The default is `false` without the `proxy-from-env` feature flag, i.e. + /// not detecting proxy from env, due to the potential security risk and to + /// maintain backward compatibility. /// /// 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 {