diff --git a/Cargo.lock b/Cargo.lock index dea83d2..f94b7f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1240,6 +1240,17 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +[[package]] +name = "socks" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b" +dependencies = [ + "byteorder", + "libc", + "winapi", +] + [[package]] name = "spin" version = "0.9.8" @@ -1548,6 +1559,7 @@ dependencies = [ "once_cell", "rustls", "rustls-webpki", + "socks", "url", "webpki-roots", ] diff --git a/Cargo.toml b/Cargo.toml index f0db03f..f5c6cb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ path-slash = "0.2.0" rustls = { version = "0.21.8", optional = true } rustls-pemfile = { version = "1.0.4", optional = true } tracing-subscriber = { version = "0.3.17", features = ["fmt"] } -ureq = { version = "2.8.0", default-features = false, features = ["gzip"] } +ureq = { version = "2.8.0", default-features = false, features = ["gzip", "socks-proxy"] } which = "5.0.0" xwin = { version = "0.5.0", default-features = false } diff --git a/src/common.rs b/src/common.rs index 4ea1b32..f1a5bb4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,7 +1,6 @@ use std::collections::HashSet; use std::convert::TryInto; use std::env; -use std::ffi::OsString; use std::path::{Path, PathBuf}; use std::process::Command; @@ -590,17 +589,8 @@ fn get_rustflags(workdir: &Path, target: &str) -> Result Result { - env::var("HTTPS_PROXY") - .or_else(|_| env::var("https_proxy")) - .or_else(|_| env::var("HTTP_PROXY")) - .or_else(|_| env::var("http_proxy")) - .or_else(|_| env::var("ALL_PROXY")) - .or_else(|_| env::var("all_proxy")) -} - #[cfg(any(feature = "native-tls", feature = "rustls"))] -fn tls_ca_bundle() -> Option { +fn tls_ca_bundle() -> Option { env::var_os("REQUESTS_CA_BUNDLE") .or_else(|| env::var_os("CURL_CA_BUNDLE")) .or_else(|| env::var_os("SSL_CERT_FILE")) @@ -612,11 +602,7 @@ fn http_agent() -> Result { use std::io; use std::sync::Arc; - let mut builder = ureq::builder(); - if let Ok(proxy) = http_proxy() { - let proxy = ureq::Proxy::new(proxy)?; - builder = builder.proxy(proxy); - }; + let mut builder = ureq::builder().try_proxy_from_env(true); let mut tls_builder = native_tls_crate::TlsConnector::builder(); if let Some(ca_bundle) = tls_ca_bundle() { let mut reader = io::BufReader::new(File::open(ca_bundle)?); @@ -634,11 +620,7 @@ fn http_agent() -> Result { use std::io; use std::sync::Arc; - let mut builder = ureq::builder(); - if let Ok(proxy) = http_proxy() { - let proxy = ureq::Proxy::new(proxy)?; - builder = builder.proxy(proxy); - }; + let builder = ureq::builder().try_proxy_from_env(true); if let Some(ca_bundle) = tls_ca_bundle() { let mut reader = io::BufReader::new(File::open(ca_bundle)?); let certs = rustls_pemfile::certs(&mut reader)?; @@ -653,3 +635,10 @@ fn http_agent() -> Result { Ok(builder.build()) } } + +#[cfg(not(any(feature = "native-tls", feature = "rustls")))] +#[allow(clippy::result_large_err)] +fn http_agent() -> Result { + let builder = ureq::builder().try_proxy_from_env(true); + Ok(builder.build()) +}