Skip to content

Commit a29c7f9

Browse files
littledivyseanmonstar
authored andcommitted
Add macos-system-configuration feature flag
1 parent 886cd81 commit a29c7f9

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ features = [
2727
]
2828

2929
[features]
30-
default = ["default-tls", "http2"]
30+
default = ["default-tls", "http2", "macos-system-configuration"]
3131

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

6868
socks = ["dep:tokio-socks"]
6969

70+
# Use the system's proxy configuration.
71+
macos-system-configuration = ["dep:system-configuration"]
72+
7073
# Experimental HTTP/3 client.
7174
# Disabled while waiting for quinn to upgrade.
7275
#http3 = ["rustls-tls-manual-roots", "dep:h3", "dep:h3-quinn", "dep:quinn", "dep:futures-channel"]
@@ -170,7 +173,7 @@ futures-util = { version = "0.3.0", default-features = false, features = ["std",
170173
winreg = "0.50.0"
171174

172175
[target.'cfg(target_os = "macos")'.dependencies]
173-
system-configuration = "0.5.1"
176+
system-configuration = { version = "0.5.1", optional = true }
174177

175178
# wasm
176179

src/proxy.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::collections::HashMap;
1313
use std::env;
1414
use std::error::Error;
1515
use std::net::IpAddr;
16-
#[cfg(target_os = "macos")]
16+
#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
1717
use system_configuration::{
1818
core_foundation::{
1919
base::CFType,
@@ -947,7 +947,7 @@ fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
947947
Ok((proxy_enable == 1).then_some(proxy_server))
948948
}
949949

950-
#[cfg(target_os = "macos")]
950+
#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
951951
fn parse_setting_from_dynamic_store(
952952
proxies_map: &CFDictionary<CFString, CFType>,
953953
enabled_key: CFStringRef,
@@ -985,7 +985,7 @@ fn parse_setting_from_dynamic_store(
985985
None
986986
}
987987

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

@@ -1016,12 +1016,18 @@ fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
10161016
}
10171017
}
10181018

1019-
#[cfg(any(target_os = "windows", target_os = "macos"))]
1019+
#[cfg(any(
1020+
target_os = "windows",
1021+
all(target_os = "macos", feature = "macos-system-configuration")
1022+
))]
10201023
fn get_from_platform() -> Option<String> {
10211024
get_from_platform_impl().ok().flatten()
10221025
}
10231026

1024-
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
1027+
#[cfg(not(any(
1028+
target_os = "windows",
1029+
all(target_os = "macos", feature = "macos-system-configuration")
1030+
)))]
10251031
fn get_from_platform() -> Option<String> {
10261032
None
10271033
}

0 commit comments

Comments
 (0)