Skip to content

Commit

Permalink
Use windows-registry instead of winreg for reading proxy settings…
Browse files Browse the repository at this point in the history
… on Windows (#2380)
  • Loading branch information
FlowerCode authored Aug 12, 2024
1 parent 5715050 commit 23f2678
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ futures-util = { version = "0.3.28", default-features = false, features = ["std"
rustls = { version = "0.23", default-features = false, features = ["ring"] }

[target.'cfg(windows)'.dependencies]
winreg = "0.52.0"
windows-registry = "0.2"

[target.'cfg(target_os = "macos")'.dependencies]
system-configuration = { version = "0.5.1", optional = true }
Expand Down
13 changes: 4 additions & 9 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ use system_configuration::{
sys::schema_definitions::kSCPropNetProxiesHTTPSPort,
sys::schema_definitions::kSCPropNetProxiesHTTPSProxy,
};
#[cfg(target_os = "windows")]
use winreg::enums::HKEY_CURRENT_USER;
#[cfg(target_os = "windows")]
use winreg::RegKey;

/// Configuration of a proxy that a `Client` should pass requests to.
///
Expand Down Expand Up @@ -937,12 +933,11 @@ fn is_cgi() -> bool {

#[cfg(target_os = "windows")]
fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
let internet_setting: RegKey =
hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")?;
let internet_setting = windows_registry::CURRENT_USER
.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")?;
// ensure the proxy is enable, if the value doesn't exist, an error will returned.
let proxy_enable: u32 = internet_setting.get_value("ProxyEnable")?;
let proxy_server: String = internet_setting.get_value("ProxyServer")?;
let proxy_enable = internet_setting.get_u32("ProxyEnable")?;
let proxy_server = internet_setting.get_string("ProxyServer")?;

Ok((proxy_enable == 1).then_some(proxy_server))
}
Expand Down

0 comments on commit 23f2678

Please sign in to comment.