From 0dbb8bbad086e54d7509cf19dbe5f527ab47b2cc Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 1 Oct 2026 00:00:00 +0000 Subject: [PATCH] feat(client/legacy): `HttpConnector` is feature flagged in hyperium/hyper-util#340 (7539356), we addressed warnings in all of the feature combinations. this commit includes further changes building upon that work, to provide a fix for hyperium/hyper#3842. users building hyper-util for certain platforms were finding that the legacy client was no longer compatible after #218 and #276, which moved the `tokio/net` feature behind the `client-legacy` flag. this led to the introduction of a dependency on `mio` via `tokio` where there was previously none, breaking builds for Fuschia and Wasm. this commit introduces a feature flag, `client-legacy-http-connector`. this commit gates the use of types like `tokio::net::TcpStream` behind this flag, which end up only being used by the legacy `HttpConnector`. this permits use of the legacy client and the connector types for alternative target platforms, while providing a way for typical users to continue to opt into this ergonomic, default connector. crate-level documentation outlining the list of features is updated to include this feature, and the `check-client-features` recipe used in CI is updated to include this feature in its exploration space. to confirm that this works for a platform like wasm, this `cargo-hack` command can be used: ``` ; cargo hack check --include-features client,client-legacy,http1,http2,client-pool --target=wasm32-wasip2 --feature-powerset ``` to confirm that other native platforms work, try this: ``` cargo hack check --include-features client,client-legacy,http1,http2,client-pool,tokio --feature-powerset ``` Signed-off-by: katelyn martin --- Cargo.toml | 4 +++- justfile | 2 +- src/client/legacy/client.rs | 4 ++-- src/client/legacy/connect/dns.rs | 9 ++++++++- src/client/legacy/connect/http.rs | 4 ++-- src/client/legacy/connect/mod.rs | 7 ++++--- src/lib.rs | 2 ++ 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 39b9c2dc..86cb5279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ default = [] full = [ "client", "client-legacy", + "client-legacy-http-connector", "client-pool", "client-proxy", "client-proxy-system", @@ -79,7 +80,8 @@ full = [ ] client = ["hyper/client", "dep:tracing", "dep:futures-channel", "dep:tower-service"] -client-legacy = ["client", "tokio/net", "dep:socket2", "tokio/sync", "dep:libc", "dep:futures-util", "dep:httparse", "dep:sync_wrapper"] +client-legacy = ["client", "tokio/sync", "dep:futures-util", "dep:httparse", "dep:sync_wrapper"] +client-legacy-http-connector = ["dep:libc", "dep:socket2", "tokio/net"] client-pool = ["client", "dep:futures-util", "dep:tower-layer", "tokio/sync"] client-proxy = ["client", "dep:base64", "dep:ipnet", "dep:percent-encoding"] client-proxy-system = ["dep:system-configuration", "dep:windows-registry"] diff --git a/justfile b/justfile index 4c84dec7..065b5034 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,7 @@ check-client-features: cargo hack --no-dev-deps check --feature-powerset --depth 2 \ --features=client \ - --include-features client-legacy,client-pool,client-proxy,client-proxy-system,http1,http2,tokio,tracing + --include-features client-legacy,client-legacy-http-connector,client-pool,client-proxy,client-proxy-system,http1,http2,tokio,tracing check-server-features: cargo hack --no-dev-deps check --feature-powerset --depth 2 \ diff --git a/src/client/legacy/client.rs b/src/client/legacy/client.rs index 9bab238e..5370e013 100644 --- a/src/client/legacy/client.rs +++ b/src/client/legacy/client.rs @@ -20,7 +20,7 @@ use hyper::{Method, Request, Response, Uri, Version, body::Body}; use sync_wrapper::SyncWrapper; use tracing::{debug, trace, warn}; -#[cfg(feature = "tokio")] +#[cfg(all(feature = "client-legacy-http-connector", feature = "tokio"))] use super::connect::HttpConnector; use super::connect::capture::CaptureConnectionExtension; use super::connect::{Alpn, Connect, Connected, Connection}; @@ -1616,7 +1616,7 @@ impl Builder { } /// Build a client with this configuration and the default `HttpConnector`. - #[cfg(feature = "tokio")] + #[cfg(all(feature = "client-legacy-http-connector", feature = "tokio"))] pub fn build_http(&self) -> Client where B: Body + Send, diff --git a/src/client/legacy/connect/dns.rs b/src/client/legacy/connect/dns.rs index 67115037..ca041274 100644 --- a/src/client/legacy/connect/dns.rs +++ b/src/client/legacy/connect/dns.rs @@ -21,7 +21,7 @@ //! }); //! ``` use std::error::Error; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; +use std::net::{SocketAddr, ToSocketAddrs}; use std::pin::Pin; use std::str::FromStr; use std::task::{self, Poll}; @@ -30,6 +30,10 @@ use std::{fmt, io, vec}; use tokio::task::JoinHandle; use tower_service::Service; +#[cfg(feature = "client-legacy-http-connector")] +use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; + +#[cfg(feature = "client-legacy-http-connector")] pub(super) use self::sealed::Resolve; /// A domain name to resolve into IP addresses. @@ -179,6 +183,7 @@ pub(super) struct SocketAddrs { iter: vec::IntoIter, } +#[cfg(feature = "client-legacy-http-connector")] impl SocketAddrs { pub(super) fn new(addrs: Vec) -> Self { SocketAddrs { @@ -249,6 +254,7 @@ impl Iterator for SocketAddrs { } } +#[cfg(all(feature = "client-legacy-http-connector"))] mod sealed { use std::task::{self, Poll}; @@ -285,6 +291,7 @@ mod sealed { } } +#[cfg(feature = "client-legacy-http-connector")] pub(super) async fn resolve(resolver: &mut R, name: Name) -> Result where R: Resolve, diff --git a/src/client/legacy/connect/http.rs b/src/client/legacy/connect/http.rs index 95af1627..745ba306 100644 --- a/src/client/legacy/connect/http.rs +++ b/src/client/legacy/connect/http.rs @@ -12,7 +12,7 @@ use futures_util::future::Either; use http::uri::{Scheme, Uri}; use pin_project_lite::pin_project; use socket2::TcpKeepalive; -use tokio::net::{TcpSocket, TcpStream}; +use tokio::net::TcpStream; use tokio::time::Sleep; use tracing::{debug, trace, warn}; @@ -941,7 +941,7 @@ fn connect( .map_err(ConnectError::m("tcp bind local error"))?; // Convert the `Socket` to a Tokio `TcpSocket`. - let socket = TcpSocket::from_std_stream(socket.into()); + let socket = tokio::net::TcpSocket::from_std_stream(socket.into()); if config.reuse_address { if let Err(e) = socket.set_reuseaddr(true) { diff --git a/src/client/legacy/connect/mod.rs b/src/client/legacy/connect/mod.rs index 47697dd2..580908d3 100644 --- a/src/client/legacy/connect/mod.rs +++ b/src/client/legacy/connect/mod.rs @@ -3,7 +3,8 @@ //! This module contains: //! //! - A default [`HttpConnector`][] that does DNS resolution and establishes -//! connections over TCP. +//! connections over TCP. This connector is gated behind the +//! `client-legacy-http-connector` feature flag. //! - Types to build custom connectors. //! //! # Connectors @@ -72,12 +73,12 @@ use std::{ use ::http::Extensions; -#[cfg(feature = "tokio")] +#[cfg(all(feature = "client-legacy-http-connector", feature = "tokio"))] pub use self::http::{HttpConnector, HttpInfo}; #[cfg(feature = "tokio")] pub mod dns; -#[cfg(feature = "tokio")] +#[cfg(all(feature = "client-legacy-http-connector", feature = "tokio"))] mod http; pub mod proxy; diff --git a/src/lib.rs b/src/lib.rs index 69535755..31644c70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,8 @@ //! * `client`: Enable [`client`] interfaces. //! * `client-legacy`: Enable the legacy //! [`Client`][crate::client::legacy::Client] implementation. +//! * `client-legacy-http-connector`: Enable the legacy +//! [`HttpConnector`][crate::client::legacy::connect::HttpConnector]. //! * `client-pool`: Enable [`client::pool`]. This submodule contains //! interfaces for constructing connection pools. //! * `client-proxy`: Enable [`client::proxy`].