Skip to content

Commit

Permalink
feat: recognise system proxy env var;
Browse files Browse the repository at this point in the history
Signed-off-by: LinHeLurking <[email protected]>
  • Loading branch information
LinHeLurking committed Jul 27, 2023
1 parent 4a2ecdf commit 826566c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt;
use std::{env, fmt};
use std::ops::Deref;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 826566c

Please sign in to comment.