Skip to content

Commit e8d89f4

Browse files
authored
enable ALPN by default in native-tls (#2907)
1 parent 9a9daa7 commit e8d89f4

7 files changed

Lines changed: 101 additions & 93 deletions

File tree

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ http2 = ["h2", "hyper/http2", "hyper-util/http2", "hyper-rustls?/http2"]
4545
rustls = ["__rustls-aws-lc-rs", "dep:rustls-platform-verifier", "__rustls"]
4646
rustls-no-provider = ["dep:rustls-platform-verifier", "__rustls"]
4747

48-
native-tls = ["dep:hyper-tls", "dep:native-tls-crate", "__tls", "dep:tokio-native-tls"]
49-
native-tls-alpn = ["native-tls", "native-tls-crate?/alpn", "hyper-tls?/alpn"]
50-
native-tls-vendored = ["native-tls", "native-tls-crate?/vendored"]
48+
native-tls = ["__native-tls", "__native-tls-alpn"]
49+
native-tls-no-alpn = ["__native-tls"]
50+
native-tls-vendored = ["__native-tls", "native-tls-crate?/vendored", "__native-tls-alpn"]
51+
native-tls-vendored-no-alpn = ["__native-tls", "native-tls-crate?/vendored"]
5152

5253
blocking = ["dep:futures-channel", "futures-channel?/sink", "dep:futures-util", "futures-util?/io", "futures-util?/sink", "tokio/sync"]
5354

@@ -89,6 +90,10 @@ __tls = ["dep:rustls-pki-types", "tokio/io-util"]
8990
__rustls = ["dep:hyper-rustls", "dep:tokio-rustls", "dep:rustls", "__tls"]
9091
__rustls-aws-lc-rs = ["hyper-rustls?/aws-lc-rs", "tokio-rustls?/aws-lc-rs", "rustls?/aws-lc-rs", "quinn?/aws-lc-rs"]
9192

93+
# Enables common native-tls code.
94+
__native-tls = ["dep:hyper-tls", "dep:native-tls-crate", "__tls", "dep:tokio-native-tls"]
95+
__native-tls-alpn = ["native-tls-crate?/alpn", "hyper-tls?/alpn"]
96+
9297
[dependencies]
9398
base64 = "0.22"
9499
http = "1.1"

src/async_impl/client.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
1+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
22
use std::any::Any;
33
use std::future::Future;
44
use std::net::IpAddr;
@@ -42,15 +42,15 @@ use crate::tls::CertificateRevocationList;
4242
use crate::tls::{self, TlsBackend};
4343
#[cfg(feature = "__tls")]
4444
use crate::Certificate;
45-
#[cfg(any(feature = "native-tls", feature = "__rustls"))]
45+
#[cfg(any(feature = "__native-tls", feature = "__rustls"))]
4646
use crate::Identity;
4747
use crate::{IntoUrl, Method, Proxy, Url};
4848

4949
use http::header::{Entry, HeaderMap, HeaderValue, ACCEPT, PROXY_AUTHORIZATION, USER_AGENT};
5050
use http::uri::Scheme;
5151
use http::Uri;
5252
use hyper_util::client::legacy::connect::HttpConnector;
53-
#[cfg(feature = "native-tls")]
53+
#[cfg(feature = "__native-tls")]
5454
use native_tls_crate::TlsConnector;
5555
use pin_project_lite::pin_project;
5656
#[cfg(feature = "http3")]
@@ -176,7 +176,7 @@ struct Config {
176176
tcp_keepalive_retries: Option<u32>,
177177
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
178178
tcp_user_timeout: Option<Duration>,
179-
#[cfg(any(feature = "native-tls", feature = "__rustls"))]
179+
#[cfg(any(feature = "__native-tls", feature = "__rustls"))]
180180
identity: Option<Identity>,
181181
proxies: Vec<ProxyMatcher>,
182182
auto_sys_proxy: bool,
@@ -312,7 +312,7 @@ impl ClientBuilder {
312312
root_certs: Vec::new(),
313313
#[cfg(feature = "__tls")]
314314
tls_certs_only: false,
315-
#[cfg(any(feature = "native-tls", feature = "__rustls"))]
315+
#[cfg(any(feature = "__native-tls", feature = "__rustls"))]
316316
identity: None,
317317
#[cfg(feature = "__rustls")]
318318
crls: vec![],
@@ -516,11 +516,11 @@ impl ClientBuilder {
516516

517517
#[cfg(feature = "__tls")]
518518
match config.tls {
519-
#[cfg(feature = "native-tls")]
519+
#[cfg(feature = "__native-tls")]
520520
TlsBackend::NativeTls => {
521521
let mut tls = TlsConnector::builder();
522522

523-
#[cfg(all(feature = "native-tls-alpn", not(feature = "http3")))]
523+
#[cfg(all(feature = "__native-tls-alpn", not(feature = "http3")))]
524524
{
525525
match config.http_version_pref {
526526
HttpVersionPref::Http1 => {
@@ -548,13 +548,13 @@ impl ClientBuilder {
548548
cert.add_to_native_tls(&mut tls);
549549
}
550550

551-
#[cfg(feature = "native-tls")]
551+
#[cfg(feature = "__native-tls")]
552552
{
553553
if let Some(id) = config.identity {
554554
id.add_to_native_tls(&mut tls)?;
555555
}
556556
}
557-
#[cfg(all(feature = "__rustls", not(feature = "native-tls")))]
557+
#[cfg(all(feature = "__rustls", not(feature = "__native-tls")))]
558558
{
559559
// Default backend + rustls Identity doesn't work.
560560
if let Some(_id) = config.identity {
@@ -606,7 +606,7 @@ impl ClientBuilder {
606606
config.tls_info,
607607
)?
608608
}
609-
#[cfg(feature = "native-tls")]
609+
#[cfg(feature = "__native-tls")]
610610
TlsBackend::BuiltNativeTls(conn) => ConnectorBuilder::from_built_native_tls(
611611
http,
612612
conn,
@@ -861,7 +861,7 @@ impl ClientBuilder {
861861
config.tls_info,
862862
)
863863
}
864-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
864+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
865865
TlsBackend::UnknownPreconfigured => {
866866
return Err(crate::error::builder(
867867
"Unknown TLS backend passed to `use_preconfigured_tls`",
@@ -1918,7 +1918,7 @@ impl ClientBuilder {
19181918
///
19191919
/// This requires the optional `native-tls` or `rustls(-...)` feature to be
19201920
/// enabled.
1921-
#[cfg(any(feature = "native-tls", feature = "__rustls"))]
1921+
#[cfg(any(feature = "__native-tls", feature = "__rustls"))]
19221922
#[cfg_attr(docsrs, doc(cfg(any(feature = "native-tls", feature = "rustls"))))]
19231923
pub fn identity(mut self, identity: Identity) -> ClientBuilder {
19241924
self.config.identity = Some(identity);
@@ -2087,15 +2087,15 @@ impl ClientBuilder {
20872087
/// # Optional
20882088
///
20892089
/// This requires the optional `native-tls` feature to be enabled.
2090-
#[cfg(feature = "native-tls")]
2090+
#[cfg(feature = "__native-tls")]
20912091
#[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
20922092
pub fn tls_backend_native(mut self) -> ClientBuilder {
20932093
self.config.tls = TlsBackend::NativeTls;
20942094
self
20952095
}
20962096

20972097
/// Deprecated: use [`ClientBuilder::tls_backend_native()`] instead.
2098-
#[cfg(feature = "native-tls")]
2098+
#[cfg(feature = "__native-tls")]
20992099
pub fn use_native_tls(self) -> ClientBuilder {
21002100
self.tls_backend_native()
21012101
}
@@ -2147,11 +2147,11 @@ impl ClientBuilder {
21472147
///
21482148
/// This requires one of the optional features `native-tls` or
21492149
/// `rustls(-...)` to be enabled.
2150-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
2150+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
21512151
#[cfg_attr(docsrs, doc(cfg(any(feature = "native-tls", feature = "rustls"))))]
21522152
pub fn tls_backend_preconfigured(mut self, tls: impl Any) -> ClientBuilder {
21532153
let mut tls = Some(tls);
2154-
#[cfg(feature = "native-tls")]
2154+
#[cfg(feature = "__native-tls")]
21552155
{
21562156
if let Some(conn) = (&mut tls as &mut dyn Any).downcast_mut::<Option<TlsConnector>>() {
21572157
let tls = conn.take().expect("is definitely Some");
@@ -2178,7 +2178,7 @@ impl ClientBuilder {
21782178
}
21792179

21802180
/// Deprecated: use [`ClientBuilder::tls_backend_preconfigured()`] instead.
2181-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
2181+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
21822182
pub fn use_preconfigured_tls(self, tls: impl Any) -> ClientBuilder {
21832183
self.tls_backend_preconfigured(tls)
21842184
}

src/blocking/client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
1+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
22
use std::any::Any;
33
use std::convert::TryInto;
44
use std::fmt;
@@ -31,7 +31,7 @@ use crate::tls;
3131
use crate::tls::CertificateRevocationList;
3232
#[cfg(feature = "__tls")]
3333
use crate::Certificate;
34-
#[cfg(any(feature = "native-tls", feature = "__rustls"))]
34+
#[cfg(any(feature = "__native-tls", feature = "__rustls"))]
3535
use crate::Identity;
3636
use crate::{async_impl, header, redirect, IntoUrl, Method, Proxy};
3737

@@ -864,7 +864,7 @@ impl ClientBuilder {
864864
///
865865
/// This requires the optional `native-tls` or `rustls(-...)` feature to be
866866
/// enabled.
867-
#[cfg(any(feature = "native-tls", feature = "__rustls"))]
867+
#[cfg(any(feature = "__native-tls", feature = "__rustls"))]
868868
#[cfg_attr(docsrs, doc(cfg(any(feature = "native-tls", feature = "rustls"))))]
869869
pub fn identity(self, identity: Identity) -> ClientBuilder {
870870
self.with_inner(move |inner| inner.identity(identity))
@@ -1014,14 +1014,14 @@ impl ClientBuilder {
10141014
/// # Optional
10151015
///
10161016
/// This requires the optional `native-tls` feature to be enabled.
1017-
#[cfg(feature = "native-tls")]
1017+
#[cfg(feature = "__native-tls")]
10181018
#[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
10191019
pub fn tls_backend_native(self) -> ClientBuilder {
10201020
self.with_inner(move |inner| inner.tls_backend_native())
10211021
}
10221022

10231023
/// Deprecated: use [`ClientBuilder::tls_backend_native()`] instead.
1024-
#[cfg(feature = "native-tls")]
1024+
#[cfg(feature = "__native-tls")]
10251025
pub fn use_native_tls(self) -> ClientBuilder {
10261026
self.with_inner(move |inner| inner.use_native_tls())
10271027
}
@@ -1080,14 +1080,14 @@ impl ClientBuilder {
10801080
///
10811081
/// This requires one of the optional features `native-tls` or
10821082
/// `rustls(-...)` to be enabled.
1083-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
1083+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
10841084
#[cfg_attr(docsrs, doc(cfg(any(feature = "native-tls", feature = "rustls"))))]
10851085
pub fn tls_backend_preconfigured(self, tls: impl Any) -> ClientBuilder {
10861086
self.with_inner(move |inner| inner.tls_backend_preconfigured(tls))
10871087
}
10881088

10891089
/// Deprecated: use [`ClientBuilder::tls_backend_preconfigured()`] instead.
1090-
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
1090+
#[cfg(any(feature = "__native-tls", feature = "__rustls",))]
10911091
pub fn use_preconfigured_tls(self, tls: impl Any) -> ClientBuilder {
10921092
self.with_inner(move |inner| inner.use_preconfigured_tls(tls))
10931093
}

0 commit comments

Comments
 (0)