Skip to content

Commit 7e74248

Browse files
authored
feat(client): add windows system proxies for Matcher (#190)
1 parent acdda1a commit 7e74248

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-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

+38
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,41 @@ mod mac {
638641
}
639642
}
640643

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

0 commit comments

Comments
 (0)