Skip to content

Commit

Permalink
Supported client proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz committed May 28, 2023
1 parent 9273a88 commit 4062b63
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ pub struct Args {
help = "exclude iface"
)]
exclude_iface: Vec<String>,
#[arg(long, env = "SSR_PROXY", default_value = "", help = "proxy")]
proxy: String,
#[arg(long, env = "SSR_NO_PROXY", default_value = "", help = "no proxy, eg: ip-api.com")]
no_proxy: String,
}

impl Args {
Expand Down Expand Up @@ -203,11 +207,21 @@ fn http_report(args: &Args, stat_base: &mut StatRequest) -> Result<()> {
stat_base.online6 = ipv6;
}

let http_client = reqwest::Client::builder()
let mut http_client_builder = reqwest::Client::builder()
.pool_max_idle_per_host(1)
.connect_timeout(Duration::from_secs(5))
.user_agent(format!("{}/{}", env!("CARGO_BIN_NAME"), env!("CARGO_PKG_VERSION")))
.build()?;
.user_agent(format!("{}/{}", env!("CARGO_BIN_NAME"), env!("CARGO_PKG_VERSION")));

if !args.proxy.is_empty() {
let mut proxy = reqwest::Proxy::all(&args.proxy)?;
if !args.no_proxy.is_empty() {
proxy = proxy.no_proxy(reqwest::NoProxy::from_string(&args.no_proxy));
}

http_client_builder = http_client_builder.proxy(proxy);
}

let http_client = http_client_builder.build()?;
loop {
let stat_rt = sample_all(args, stat_base);

Expand Down

0 comments on commit 4062b63

Please sign in to comment.