Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macos-system-configuration feature flag #2185

Merged
merged 1 commit into from
Mar 18, 2024
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
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ features = [
]

[features]
default = ["default-tls", "http2"]
default = ["default-tls", "http2", "macos-system-configuration"]

# Note: this doesn't enable the 'native-tls' feature, which adds specific
# functionality for it.
Expand Down Expand Up @@ -65,6 +65,9 @@ stream = ["tokio/fs", "dep:tokio-util", "dep:wasm-streams"]

socks = ["dep:tokio-socks"]

# Use the system's proxy configuration.
macos-system-configuration = ["dep:system-configuration"]

# Experimental HTTP/3 client.
# Disabled while waiting for quinn to upgrade.
#http3 = ["rustls-tls-manual-roots", "dep:h3", "dep:h3-quinn", "dep:quinn", "dep:futures-channel"]
Expand Down Expand Up @@ -168,7 +171,7 @@ futures-util = { version = "0.3.0", default-features = false, features = ["std",
winreg = "0.50.0"

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

# wasm

Expand Down
16 changes: 11 additions & 5 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::net::IpAddr;
#[cfg(target_os = "macos")]
#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
use system_configuration::{
core_foundation::{
base::CFType,
Expand Down Expand Up @@ -947,7 +947,7 @@ fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
Ok((proxy_enable == 1).then_some(proxy_server))
}

#[cfg(target_os = "macos")]
#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
fn parse_setting_from_dynamic_store(
proxies_map: &CFDictionary<CFString, CFType>,
enabled_key: CFStringRef,
Expand Down Expand Up @@ -985,7 +985,7 @@ fn parse_setting_from_dynamic_store(
None
}

#[cfg(target_os = "macos")]
#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
let store = SCDynamicStoreBuilder::new("reqwest").build();

Expand Down Expand Up @@ -1016,12 +1016,18 @@ fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
}
}

#[cfg(any(target_os = "windows", target_os = "macos"))]
#[cfg(any(
target_os = "windows",
all(target_os = "macos", feature = "macos-system-configuration")
))]
fn get_from_platform() -> Option<String> {
get_from_platform_impl().ok().flatten()
}

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
#[cfg(not(any(
target_os = "windows",
all(target_os = "macos", feature = "macos-system-configuration")
)))]
fn get_from_platform() -> Option<String> {
None
}
Expand Down