Skip to content

Commit

Permalink
Adds support for ALL_PROXY (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
smndtrl committed May 30, 2023
1 parent 280af15 commit cec216b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@ fn get_from_environment() -> SystemProxyMap {
insert_from_env(&mut proxies, "https", "https_proxy");
}

if !(insert_from_env(&mut proxies, "http", "ALL_PROXY")
&& insert_from_env(&mut proxies, "https", "ALL_PROXY"))
{
insert_from_env(&mut proxies, "http", "all_proxy");
insert_from_env(&mut proxies, "https", "all_proxy");
}

proxies
}

Expand Down Expand Up @@ -1134,6 +1141,7 @@ mod tests {
// save system setting first.
let _g1 = env_guard("HTTP_PROXY");
let _g2 = env_guard("http_proxy");
let _g3 = env_guard("ALL_PROXY");

// Mock ENV, get the results, before doing assertions
// to avoid assert! -> panic! -> Mutex Poisoned.
Expand All @@ -1144,6 +1152,9 @@ mod tests {
// set valid proxy
env::set_var("http_proxy", "127.0.0.1/");
let valid_proxies = get_sys_proxies(None);
// set valid ALL_PROXY
env::set_var("ALL_PROXY", "127.0.0.2/");
let all_proxies = get_sys_proxies(None);

// reset user setting when guards drop
drop(_g1);
Expand All @@ -1157,6 +1168,9 @@ mod tests {
let p = &valid_proxies["http"];
assert_eq!(p.scheme(), "http");
assert_eq!(p.host(), "127.0.0.1");

assert_eq!(all_proxies.len(), 2);
assert!(all_proxies.values().all(|p| p.host() == "127.0.0.2"));
}

#[cfg(target_os = "windows")]
Expand Down

0 comments on commit cec216b

Please sign in to comment.