Skip to content

Commit 377fa88

Browse files
committed
feat(client): add windows system proxies for Matcher
1 parent acdda1a commit 377fa88

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pnet_datalink = "0.35.0"
4848
[target.'cfg(target_os = "macos")'.dependencies]
4949
system-configuration = { version = "0.6.1", optional = true }
5050

51+
[target.'cfg(windows)'.dependencies]
52+
windows-registry = { version = "0.4", optional = true }
53+
5154
[features]
5255
default = []
5356

@@ -68,7 +71,7 @@ full = [
6871
client = ["hyper/client", "dep:tracing", "dep:futures-channel", "dep:tower-service"]
6972
client-legacy = ["client", "dep:socket2", "tokio/sync", "dep:libc"]
7073
client-proxy = ["client", "dep:base64", "dep:ipnet", "dep:percent-encoding"]
71-
client-proxy-system = ["dep:system-configuration"]
74+
client-proxy-system = ["dep:system-configuration", "dep:windows-registry"]
7275

7376
server = ["hyper/server"]
7477
server-auto = ["server", "http1", "http2"]

src/client/proxy/matcher.rs

+40
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ impl Builder {
242242
#[cfg(all(feature = "client-proxy-system", target_os = "macos"))]
243243
mac::with_system(&mut builder);
244244

245+
#[cfg(all(feature = "client-proxy-system", windows))]
246+
win::with_system(&mut builder);
247+
245248
builder
246249
}
247250

@@ -638,6 +641,43 @@ mod mac {
638641
}
639642
}
640643

644+
#[cfg(feature = "client-proxy-system")]
645+
#[cfg(windows)]
646+
mod win {
647+
use windows_registry::CURRENT_USER;
648+
649+
pub(super) fn with_system(builder: &mut super::Builder) {
650+
let settings = if let Ok(settings) = windows_registry::CURRENT_USER
651+
.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
652+
{
653+
settings
654+
} else {
655+
return;
656+
};
657+
658+
if settings.get_u32("ProxyEnable").unwrap_or(0) == 0 {
659+
return;
660+
}
661+
662+
if builder.http.is_empty() {
663+
if let Ok(val) = settings.get_string("ProxyServer") {
664+
builder.http = val;
665+
}
666+
}
667+
668+
if builder.no.is_empty() {
669+
if let Ok(val) = settings.get_string("") {
670+
builder.no = value
671+
.split(';')
672+
.map(|s| s.trim())
673+
.collect::<Vec<&str>>()
674+
.join(",")
675+
.replace("*.", "");
676+
}
677+
}
678+
}
679+
}
680+
641681
#[cfg(test)]
642682
mod tests {
643683
use super::*;

0 commit comments

Comments
 (0)