Skip to content

Commit

Permalink
Use builtin http proxy support from ureq
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 19, 2023
1 parent e1b315f commit 144268b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
31 changes: 10 additions & 21 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -590,17 +589,8 @@ fn get_rustflags(workdir: &Path, target: &str) -> Result<Option<cargo_config2::F
Ok(rustflags)
}

fn http_proxy() -> Result<String, env::VarError> {
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<OsString> {
fn tls_ca_bundle() -> Option<std::ffi::OsString> {
env::var_os("REQUESTS_CA_BUNDLE")
.or_else(|| env::var_os("CURL_CA_BUNDLE"))
.or_else(|| env::var_os("SSL_CERT_FILE"))
Expand All @@ -612,11 +602,7 @@ fn http_agent() -> Result<ureq::Agent> {
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)?);
Expand All @@ -634,11 +620,7 @@ fn http_agent() -> Result<ureq::Agent> {
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)?;
Expand All @@ -653,3 +635,10 @@ fn http_agent() -> Result<ureq::Agent> {
Ok(builder.build())
}
}

#[cfg(not(any(feature = "native-tls", feature = "rustls")))]
#[allow(clippy::result_large_err)]
fn http_agent() -> Result<ureq::Agent> {
let builder = ureq::builder().try_proxy_from_env(true);
Ok(builder.build())
}

0 comments on commit 144268b

Please sign in to comment.