diff --git a/Cargo.toml b/Cargo.toml index cda2b9a6..744d04fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,9 @@ webpki-roots = ["dep:webpki-root-certs"] # Use the system's proxy configuration. macos-system-configuration = ["dep:system-configuration"] +# Use the Apple platform's network device binding. +apple-bindable-device = ["dep:libc"] + # Optional enable http2 tracing http2-tracing = ["hyper2/http2-tracing"] @@ -153,7 +156,7 @@ windows-registry = "0.4.0" system-configuration = { version = "0.6.0", optional = true } [target.'cfg(any(target_os = "ios", target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos"))'.dependencies] -libc = "0.2" +libc = { version = "0.2", optional = true } [dev-dependencies] hyper = { version = "1.1.0", default-features = false, features = [ @@ -308,6 +311,7 @@ required-features = ["websocket", "http2-tracing", "futures-util/std"] [[example]] name = "client_chain" path = "examples/client_chain.rs" +required-features = ["apple-bindable-device"] [[example]] name = "request_with_redirect" diff --git a/examples/client_chain.rs b/examples/client_chain.rs index b66e6a45..947b94a5 100644 --- a/examples/client_chain.rs +++ b/examples/client_chain.rs @@ -30,7 +30,7 @@ async fn main() -> Result<(), rquest::Error> { .as_mut() .impersonate(Impersonate::Safari18) .headers_order(HEADER_ORDER) - .interface("utun4") + .interface("utun6") .apply()?; let text = client diff --git a/src/lib.rs b/src/lib.rs index d83067d1..1f7339c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -286,11 +286,16 @@ macro_rules! cfg_bindable_device { target_os = "android", target_os = "fuchsia", target_os = "linux", - target_os = "ios", - target_os = "visionos", - target_os = "macos", - target_os = "tvos", - target_os = "watchos" + all( + feature = "apple-bindable-device", + any( + target_os = "ios", + target_os = "visionos", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ) + ) ))] $( $tt @@ -306,11 +311,16 @@ macro_rules! cfg_non_bindable_device { target_os = "android", target_os = "fuchsia", target_os = "linux", - target_os = "ios", - target_os = "visionos", - target_os = "macos", - target_os = "tvos", - target_os = "watchos" + all( + feature = "apple-bindable-device", + any( + target_os = "ios", + target_os = "visionos", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ) + ) )))] $( $tt diff --git a/src/util/client/connect/http.rs b/src/util/client/connect/http.rs index e425ea7f..a7c04cf6 100644 --- a/src/util/client/connect/http.rs +++ b/src/util/client/connect/http.rs @@ -81,11 +81,16 @@ struct Config { target_os = "android", target_os = "fuchsia", target_os = "linux", - target_os = "ios", - target_os = "visionos", - target_os = "macos", - target_os = "tvos", - target_os = "watchos", + all( + feature = "apple-bindable-device", + any( + target_os = "ios", + target_os = "visionos", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ) + ) ))] interface: Option>, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] @@ -246,11 +251,16 @@ impl HttpConnector { target_os = "android", target_os = "fuchsia", target_os = "linux", - target_os = "ios", - target_os = "visionos", - target_os = "macos", - target_os = "tvos", - target_os = "watchos", + all( + feature = "apple-bindable-device", + any( + target_os = "ios", + target_os = "visionos", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ) + ) ))] interface: None, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] @@ -812,12 +822,15 @@ fn connect( .map_err(ConnectError::m("tcp bind interface error"))?; } - #[cfg(any( - target_os = "ios", - target_os = "visionos", - target_os = "macos", - target_os = "tvos", - target_os = "watchos", + #[cfg(all( + feature = "apple-bindable-device", + any( + target_os = "ios", + target_os = "visionos", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ) ))] /// That this only supports ios, visionos, macos, tvos, watchos if let Some(interface) = &config.interface {