Skip to content

Commit

Permalink
fix: proxy using AutoConfigUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Kosette committed Nov 21, 2024
1 parent 6a1f895 commit 5f1b34f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ fn main() {
#[cfg(windows)]
{
println!("cargo:rerun-if-changed=tsukimi-manifest.rc");
embed_resource::compile("./tsukimi_manifest.rc", embed_resource::NONE);
embed_resource::compile("./tsukimi_manifest.rc", embed_resource::NONE)
.manifest_optional()
.unwrap();
}
}
25 changes: 19 additions & 6 deletions src/client/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ReqClient {

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

tower::ServiceBuilder::new()
.concurrency_limit(SETTINGS.threads() as usize)
.service(client)
Expand All @@ -63,15 +63,28 @@ use 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);
if WinHttpGetIEProxyConfigForCurrentUser(&mut proxy_config).is_err() {
return None;
}

if !proxy_config.lpszProxy.is_null() {
return PCWSTR(proxy_config.lpszProxy.0).to_string().ok();
}

if !proxy_config.lpszAutoConfigUrl.is_null() {
return PCWSTR(proxy_config.lpszAutoConfigUrl.0)
.to_string()
.map(|proxy_url| {
proxy_url.split('/').collect::<Vec<_>>()[..3]
.join("/")
.to_string()
})
.ok();
}
}
None
}

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

0 comments on commit 5f1b34f

Please sign in to comment.