diff --git a/src/agent.rs b/src/agent.rs index 1a76dcfc..6dcfa33e 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::{env, fmt}; use std::ops::Deref; use std::sync::Arc; use std::time::Duration; @@ -249,9 +249,17 @@ const DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST: usize = 1; impl AgentBuilder { pub fn new() -> Self { + let names = ["http_proxy", "HTTP_PROXY", "https_proxy", "HTTPS_PROXY", + "socks_proxy", "SOCKS_PROXY", "socks5_proxy", "SOCKS5_PROXY"]; + let proxy = names.iter().find_map(|&name| { + env::var(name).ok() + }).map(|addr| { + println!("Using proxy: {}", addr); + Proxy::new(addr).ok() + }).flatten(); AgentBuilder { config: AgentConfig { - proxy: None, + proxy, timeout_connect: Some(Duration::from_secs(30)), timeout_read: None, timeout_write: None,