From e5472e011b3a3587c60c04d0c2bd8ecc177a69b9 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Wed, 10 Feb 2021 15:26:08 +0100 Subject: [PATCH 1/3] fix: Only report http2 support if the http2 feature is enabled Fixes https://github.com/ctz/hyper-rustls/issues/143 --- Cargo.toml | 1 + src/connector.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 73f1643..e0783fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ futures-util = { version = "0.3.1", default-features = false } [features] default = ["native-tokio"] +http2 = ["hyper/http2"] webpki-tokio = ["tokio-runtime", "webpki-roots"] native-tokio = ["tokio-runtime", "rustls-native-certs"] tokio-runtime = ["hyper/runtime", "ct-logs"] diff --git a/src/connector.rs b/src/connector.rs index 76dbf52..811b5c1 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -61,7 +61,15 @@ impl HttpsConnector { let mut http = HttpConnector::new(); http.enforce_http(false); - config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + #[cfg(feature = "http2")] + { + config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + } + #[cfg(not(feature = "http2"))] + { + config.alpn_protocols = vec![b"http/1.1".to_vec()]; + } + config.ct_logs = Some(&ct_logs::LOGS); (http, config).into() } From cf9df119516605d4eedca90117f51d9b13905670 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Thu, 11 Feb 2021 11:10:58 +0100 Subject: [PATCH 2/3] nit --- src/connector.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/connector.rs b/src/connector.rs index 811b5c1..3f42bb7 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -65,10 +65,6 @@ impl HttpsConnector { { config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; } - #[cfg(not(feature = "http2"))] - { - config.alpn_protocols = vec![b"http/1.1".to_vec()]; - } config.ct_logs = Some(&ct_logs::LOGS); (http, config).into() From 31cae44ec8a53010175028a874ee7ff13be2555a Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Mon, 15 Feb 2021 11:59:19 +0100 Subject: [PATCH 3/3] Also add a http1 feature (enabled by default) --- Cargo.toml | 3 ++- src/connector.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0783fc..f441aea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,8 @@ hyper = { version = "0.14", features = ["full"] } futures-util = { version = "0.3.1", default-features = false } [features] -default = ["native-tokio"] +default = ["native-tokio", "http1"] +http1 = ["hyper/http1"] http2 = ["hyper/http2"] webpki-tokio = ["tokio-runtime", "webpki-roots"] native-tokio = ["tokio-runtime", "rustls-native-certs"] diff --git a/src/connector.rs b/src/connector.rs index 3f42bb7..48b75a7 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -61,9 +61,15 @@ impl HttpsConnector { let mut http = HttpConnector::new(); http.enforce_http(false); + config.alpn_protocols.clear(); #[cfg(feature = "http2")] { - config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + config.alpn_protocols.push(b"h2".to_vec()); + } + + #[cfg(feature = "http1")] + { + config.alpn_protocols.push(b"http/1.1".to_vec()); } config.ct_logs = Some(&ct_logs::LOGS);