Skip to content

Commit

Permalink
feat: support all proxy env vars including NO_PROXY (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Nov 27, 2024
1 parent 2003159 commit 59df81b
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<reqwest::ClientBuilder> {
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)
}

Expand Down

0 comments on commit 59df81b

Please sign in to comment.