From 8e6cb34cdb20c0f644bebb1ed28d3298214327a9 Mon Sep 17 00:00:00 2001 From: tsukinaha Date: Wed, 20 Nov 2024 21:47:17 +0800 Subject: [PATCH] Fix win proxy init Signed-off-by: tsukinaha --- src/client/proxy.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/client/proxy.rs b/src/client/proxy.rs index 40816b92..89b9733c 100644 --- a/src/client/proxy.rs +++ b/src/client/proxy.rs @@ -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) @@ -66,4 +78,4 @@ pub fn get_proxy_settings() -> Option { env::var("http_proxy") .or_else(|_| env::var("https_proxy")) .ok() -} \ No newline at end of file +}