Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pnet_datalink = "0.35.0"
[target.'cfg(target_os = "macos")'.dependencies]
system-configuration = { version = "0.6.1", optional = true }

[target.'cfg(windows)'.dependencies]
windows-registry = { version = "0.4", optional = true }

[features]
default = []

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

server = ["hyper/server"]
server-auto = ["server", "http1", "http2"]
Expand Down
38 changes: 38 additions & 0 deletions src/client/proxy/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ impl Builder {
#[cfg(all(feature = "client-proxy-system", target_os = "macos"))]
mac::with_system(&mut builder);

#[cfg(all(feature = "client-proxy-system", windows))]
win::with_system(&mut builder);

builder
}

Expand Down Expand Up @@ -638,6 +641,41 @@ mod mac {
}
}

#[cfg(feature = "client-proxy-system")]
#[cfg(windows)]
mod win {
pub(super) fn with_system(builder: &mut super::Builder) {
let settings = if let Ok(settings) = windows_registry::CURRENT_USER
.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
{
settings
} else {
return;
};

if settings.get_u32("ProxyEnable").unwrap_or(0) == 0 {
return;
}

if builder.http.is_empty() {
if let Ok(val) = settings.get_string("ProxyServer") {
builder.http = val;
}
}

if builder.no.is_empty() {
if let Ok(val) = settings.get_string("ProxyOverride") {
builder.no = val
.split(';')
.map(|s| s.trim())
.collect::<Vec<&str>>()
.join(",")
.replace("*.", "");
}
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading