Skip to content

Commit 00b15b9

Browse files
authored
fix using Windows ProxyOverride registry value as a NO_PROXY (#2559)
Closes #1444
1 parent 0cf27a9 commit 00b15b9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ futures-util = { version = "0.3.28", default-features = false, features = ["std"
181181
rustls = { version = "0.23", default-features = false, features = ["ring"] }
182182

183183
[target.'cfg(windows)'.dependencies]
184-
windows-registry = "0.2"
184+
windows-registry = "0.4"
185185

186186
[target.'cfg(target_os = "macos")'.dependencies]
187187
system-configuration = { version = "0.6.0", optional = true }

src/proxy.rs

+28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use system_configuration::{
2929
sys::schema_definitions::kSCPropNetProxiesHTTPSProxy,
3030
};
3131

32+
#[cfg(target_os = "windows")]
33+
use windows_registry::CURRENT_USER;
34+
3235
/// Configuration of a proxy that a `Client` should pass requests to.
3336
///
3437
/// A `Proxy` has a couple pieces to it:
@@ -280,6 +283,13 @@ impl Proxy {
280283
get_from_platform(),
281284
))));
282285
proxy.no_proxy = NoProxy::from_env();
286+
287+
#[cfg(target_os = "windows")]
288+
{
289+
let win_exceptions: String = get_windows_proxy_exceptions();
290+
proxy.no_proxy = NoProxy::from_string(&win_exceptions);
291+
}
292+
283293
proxy
284294
}
285295

@@ -1136,6 +1146,24 @@ fn parse_platform_values(platform_values: String) -> SystemProxyMap {
11361146
parse_platform_values_impl(platform_values)
11371147
}
11381148

1149+
#[cfg(target_os = "windows")]
1150+
fn get_windows_proxy_exceptions() -> String {
1151+
let mut exceptions = String::new();
1152+
if let Ok(key) =
1153+
CURRENT_USER.create(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings")
1154+
{
1155+
if let Ok(value) = key.get_string("ProxyOverride") {
1156+
exceptions = value
1157+
.split(';')
1158+
.map(|s| s.trim())
1159+
.collect::<Vec<&str>>()
1160+
.join(",")
1161+
.replace("*.", "");
1162+
}
1163+
}
1164+
exceptions
1165+
}
1166+
11391167
#[cfg(test)]
11401168
mod tests {
11411169
use super::*;

0 commit comments

Comments
 (0)