Skip to content

Commit

Permalink
Remove http proxy
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 7cf7e75 commit 5e37f5b
Showing 1 changed file with 5 additions and 50 deletions.
55 changes: 5 additions & 50 deletions src/client/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,15 @@ impl ReqClient {
pub fn build() -> ConcurrencyLimit<Client> {
let settings = gtk::gio::Settings::new(crate::APP_ID);

let client_builder = reqwest::Client::builder()
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);

let client = if let Some(proxy_url) = get_proxy_settings() {
match reqwest::Proxy::all(proxy_url) {
Ok(proxy) => client_builder.proxy(proxy),
Err(_) => {
tracing::warn!("Failed to set proxy settings, using default client");
client_builder
}
}
} else {
client_builder
}
.build()
.expect("failed to initialize client");
.pool_max_idle_per_host(settings.int("threads") as usize)
.build()
.expect("failed to initialize client");

tower::ServiceBuilder::new()
.concurrency_limit(SETTINGS.threads() as usize)
.service(client)
}
}

#[cfg(target_os = "windows")]
use windows::{
core::PCWSTR,
Win32::Networking::WinHttp::{
WinHttpGetIEProxyConfigForCurrentUser,
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG,
},
};

#[cfg(target_os = "windows")]
pub fn get_proxy_settings() -> Option<String> {
unsafe {
let mut proxy_config = WINHTTP_CURRENT_USER_IE_PROXY_CONFIG::default();

if WinHttpGetIEProxyConfigForCurrentUser(&mut proxy_config).is_ok()
&& !proxy_config.lpszProxy.is_null()
{
let proxy = PCWSTR(proxy_config.lpszProxy.0).to_string().unwrap();
return Some(proxy);
}
}
None
}

#[cfg(target_os = "linux")]
pub fn get_proxy_settings() -> Option<String> {
use std::env;

env::var("http_proxy")
.or_else(|_| env::var("https_proxy"))
.ok()
}
}

0 comments on commit 5e37f5b

Please sign in to comment.