Skip to content

Commit

Permalink
Fix win proxy init
Browse files Browse the repository at this point in the history
Signed-off-by: tsukinaha <sakuovds@gmail.com>
  • Loading branch information
tsukinaha committed Nov 20, 2024
1 parent bedb353 commit 8e6cb34
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/client/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,26 @@ impl ReqClient {
.expect("failed to initialize client");

#[cfg(target_os = "windows")]
let client = reqwest::Client::builder()
.user_agent(APP_USER_AGENT.to_string())
.timeout(std::time::Duration::from_secs(10))
.pool_max_idle_per_host(settings.int("threads") as usize)
.proxy(reqwest::Proxy::all(get_proxy_settings().unwrap_or_default()))
.build()
.expect("failed to initialize client");
let client = {
let client_builder = reqwest::Client::builder()
.user_agent(APP_USER_AGENT.to_string())
.timeout(std::time::Duration::from_secs(10))
.pool_max_idle_per_host(settings.int("threads") as usize);

let client_builder = match get_proxy_settings() {
Some(proxy_settings) => {
if let Ok(proxy) = reqwest::Proxy::all(proxy_settings) {
client_builder.proxy(proxy)
} else {
client_builder
}
}
_ => client_builder,
};

client_builder.build().expect("failed to initialize client")
};

tower::ServiceBuilder::new()
.concurrency_limit(SETTINGS.threads() as usize)
.service(client)
Expand Down Expand Up @@ -66,4 +78,4 @@ pub fn get_proxy_settings() -> Option<String> {
env::var("http_proxy")
.or_else(|_| env::var("https_proxy"))
.ok()
}
}

0 comments on commit 8e6cb34

Please sign in to comment.