Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for ALL_PROXY #1856

Merged
merged 3 commits into from
May 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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