From 93b75e5f9c62d2ca8b2ffefb56371fb553fbc0db Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Nov 2023 20:48:14 -0500 Subject: [PATCH] chore: hide internal features * In `Cargo.toml`, hide all optional dependencies as features Currently, reqwest publishes all optional dependencies as features - which is usually not what is intended. Instead, the features should be explicitly declared, whereas optional features are enabled with the new `dep:*` syntax. Note that I also had to fix a few conditional compilations which used optional crates rather than features as conditionals. Also, note the use of the `...?/...` syntax instead of `.../...` -- as this both enabled an optional crate AND adds a feature to it. Now, it uses the `"dep:...", "...?/..."` syntax to prevent exposing crate name. --- Cargo.toml | 40 ++++++++++++++++++++-------------------- src/async_impl/client.rs | 4 ++-- src/connect.rs | 2 +- src/tls.rs | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 11bf77fba8..8c3bf225f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,40 +31,40 @@ default = ["default-tls"] # Note: this doesn't enable the 'native-tls' feature, which adds specific # functionality for it. -default-tls = ["hyper-tls", "native-tls-crate", "__tls", "tokio-native-tls"] +default-tls = ["dep:hyper-tls", "dep:native-tls-crate", "__tls", "dep:tokio-native-tls"] # Enables native-tls specific functionality not available by default. native-tls = ["default-tls"] -native-tls-alpn = ["native-tls", "native-tls-crate/alpn"] -native-tls-vendored = ["native-tls", "native-tls-crate/vendored"] +native-tls-alpn = ["native-tls", "native-tls-crate?/alpn"] +native-tls-vendored = ["native-tls", "native-tls-crate?/vendored"] rustls-tls = ["rustls-tls-webpki-roots"] rustls-tls-manual-roots = ["__rustls"] -rustls-tls-webpki-roots = ["webpki-roots", "__rustls"] -rustls-tls-native-roots = ["rustls-native-certs", "__rustls"] +rustls-tls-webpki-roots = ["dep:webpki-roots", "__rustls"] +rustls-tls-native-roots = ["dep:rustls-native-certs", "__rustls"] blocking = ["futures-util/io", "tokio/rt-multi-thread", "tokio/sync"] -cookies = ["cookie_crate", "cookie_store"] +cookies = ["dep:cookie_crate", "dep:cookie_store"] -gzip = ["async-compression", "async-compression/gzip", "tokio-util"] +gzip = ["dep:async-compression", "async-compression?/gzip", "dep:tokio-util"] -brotli = ["async-compression", "async-compression/brotli", "tokio-util"] +brotli = ["dep:async-compression", "async-compression?/brotli", "dep:tokio-util"] -deflate = ["async-compression", "async-compression/zlib", "tokio-util"] +deflate = ["dep:async-compression", "async-compression?/zlib", "dep:tokio-util"] -json = ["serde_json"] +json = ["dep:serde_json"] -multipart = ["mime_guess"] +multipart = ["dep:mime_guess"] -trust-dns = ["trust-dns-resolver"] +trust-dns = ["dep:trust-dns-resolver"] -stream = ["tokio/fs", "tokio-util", "wasm-streams"] +stream = ["tokio/fs", "dep:tokio-util", "dep:wasm-streams"] -socks = ["tokio-socks"] +socks = ["dep:tokio-socks"] # Experimental HTTP/3 client. -http3 = ["rustls-tls-manual-roots", "h3", "h3-quinn", "quinn", "futures-channel"] +http3 = ["rustls-tls-manual-roots", "dep:h3", "dep:h3-quinn", "dep:quinn", "dep:futures-channel"] # Internal (PRIVATE!) features used to aid testing. # Don't rely on these whatsoever. They may disappear at anytime. @@ -74,7 +74,7 @@ __tls = [] # Enables common rustls code. # Equivalent to rustls-tls-manual-roots but shorter :) -__rustls = ["hyper-rustls", "tokio-rustls", "rustls", "__tls", "rustls-pemfile"] +__rustls = ["dep:hyper-rustls", "dep:tokio-rustls", "dep:rustls", "__tls", "dep:rustls-pemfile"] # When enabled, disable using the cached SYS_PROXIES. __internal_proxy_sys_no_cache = [] @@ -140,10 +140,10 @@ tokio-socks = { version = "0.5.1", optional = true } trust-dns-resolver = { version = "0.23", optional = true, features = ["tokio-runtime"] } # HTTP/3 experimental support -h3 = { version="0.0.3", optional = true } -h3-quinn = { version="0.0.4", optional = true } -quinn = { version = "0.10", default-features = false, features = ["tls-rustls", "ring", "runtime-tokio"], optional = true } -futures-channel = { version="0.3", optional = true} +h3 = { version = "0.0.3", optional = true } +h3-quinn = { version = "0.0.4", optional = true } +quinn = { version = "0.10", default-features = false, features = ["tls-rustls", "ring", "runtime-tokio"], optional = true } +futures-channel = { version = "0.3", optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 21df312b26..9b4f3df4ad 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -14,7 +14,7 @@ use http::header::{ use http::uri::Scheme; use http::Uri; use hyper::client::{HttpConnector, ResponseFuture as HyperResponseFuture}; -#[cfg(feature = "native-tls-crate")] +#[cfg(feature = "default-tls")] use native_tls_crate::TlsConnector; use pin_project_lite::pin_project; use std::future::Future; @@ -2026,7 +2026,7 @@ impl Config { f.field("tls_info", &self.tls_info); } - #[cfg(all(feature = "native-tls-crate", feature = "__rustls"))] + #[cfg(all(feature = "default-tls", feature = "__rustls"))] { f.field("tls_backend", &self.tls); } diff --git a/src/connect.rs b/src/connect.rs index 2fdcd56c0d..07987a87f1 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -4,7 +4,7 @@ use http::uri::{Authority, Scheme}; use http::Uri; use hyper::client::connect::{Connected, Connection}; use hyper::service::Service; -#[cfg(feature = "native-tls-crate")] +#[cfg(feature = "default-tls")] use native_tls_crate::{TlsConnector, TlsConnectorBuilder}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; diff --git a/src/tls.rs b/src/tls.rs index 8d65773943..bc54c3947d 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -21,7 +21,7 @@ use std::fmt; /// Represents a server X509 certificate. #[derive(Clone)] pub struct Certificate { - #[cfg(feature = "native-tls-crate")] + #[cfg(feature = "default-tls")] native: native_tls_crate::Certificate, #[cfg(feature = "__rustls")] original: Cert, @@ -73,7 +73,7 @@ impl Certificate { /// ``` pub fn from_der(der: &[u8]) -> crate::Result { Ok(Certificate { - #[cfg(feature = "native-tls-crate")] + #[cfg(feature = "default-tls")] native: native_tls_crate::Certificate::from_der(der).map_err(crate::error::builder)?, #[cfg(feature = "__rustls")] original: Cert::Der(der.to_owned()), @@ -98,14 +98,14 @@ impl Certificate { /// ``` pub fn from_pem(pem: &[u8]) -> crate::Result { Ok(Certificate { - #[cfg(feature = "native-tls-crate")] + #[cfg(feature = "default-tls")] native: native_tls_crate::Certificate::from_pem(pem).map_err(crate::error::builder)?, #[cfg(feature = "__rustls")] original: Cert::Pem(pem.to_owned()), }) } - #[cfg(feature = "native-tls-crate")] + #[cfg(feature = "default-tls")] pub(crate) fn add_to_native_tls(self, tls: &mut native_tls_crate::TlsConnectorBuilder) { tls.add_root_certificate(self.native); }