From 59df81b41cc91d93da465e32a9500ee614b18c11 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 27 Nov 2024 10:16:21 +0800 Subject: [PATCH] feat: support all proxy env vars including NO_PROXY (#1015) --- src/utils/mod.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 27dac4a5..873c5c88 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -208,24 +208,17 @@ pub fn is_url(path: &str) -> bool { } pub fn set_proxy( - builder: reqwest::ClientBuilder, + mut builder: reqwest::ClientBuilder, proxy: Option<&String>, ) -> Result { - let proxy = if let Some(proxy) = proxy { - if proxy.is_empty() || proxy == "-" { - return Ok(builder); + if let Some(proxy) = proxy { + builder = builder.no_proxy(); + if !proxy.is_empty() && proxy != "-" { + builder = builder.proxy( + reqwest::Proxy::all(proxy).with_context(|| format!("Invalid proxy `{proxy}`"))?, + ); } - proxy.clone() - } else if let Some(proxy) = ["HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy"] - .into_iter() - .find_map(|v| env::var(v).ok()) - { - proxy - } else { - return Ok(builder); }; - let builder = builder - .proxy(reqwest::Proxy::all(&proxy).with_context(|| format!("Invalid proxy `{proxy}`"))?); Ok(builder) }