Skip to content

Commit 55d3e32

Browse files
committed
Refactor!: Introduce a Cargo feature for optional Hyper 0 support
Closes #294. Requires breaking changes, but only regarding the `hyper1` feature's enabled module path; the default v0 is still preserved. What is proposed here in order to achieve the objective is to have both modules be re-exported when the other feature is not enabled, and have them be made public when both features are enabled at the same time. This way, the features should be kept additive: all four combinations are supported. It enables dependency de-duplication when consuming it. Signed-off-by: Paul Mabileau <[email protected]>
1 parent 4685af0 commit 55d3e32

File tree

8 files changed

+48
-26
lines changed

8 files changed

+48
-26
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,7 @@ jobs:
366366
name: Run `rpk,underscore-wildcards` tests
367367
- run: cargo test --features pq-experimental,rpk,underscore-wildcards
368368
name: Run `pq-experimental,rpk,underscore-wildcards` tests
369+
- run: cargo test -p hyper-boring --features hyper0
370+
name: Run hyper 0. tests for hyper-boring
369371
- run: cargo test -p hyper-boring --features hyper1
370372
name: Run hyper 1.0 tests for hyper-boring

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ anyhow = "1"
3939
antidote = "1.0.0"
4040
http = "1"
4141
http-body-util = "0.1.2"
42-
http_old = { package = "http", version = "0.2" }
43-
hyper = "1"
42+
http0 = { package = "http", version = "0.2" }
43+
hyper1 = { package = "hyper", version = "1" }
4444
hyper-util = "0.1.6"
45-
hyper_old = { package = "hyper", version = "0.14", default-features = false }
45+
hyper0 = { package = "hyper", version = "0.14", default-features = false }
4646
linked_hash_set = "0.1"
4747
once_cell = "1.0"
4848
openssl-macros = "0.1.1"

hyper-boring/Cargo.toml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ features = ["pq-experimental"]
1515
rustdoc-args = ["--cfg", "docsrs"]
1616

1717
[features]
18-
default = ["runtime"]
18+
default = ["runtime", "hyper0-runtime"]
1919

20-
runtime = ["hyper_old/runtime"]
20+
runtime = []
21+
hyper0-runtime = ["hyper0", "hyper0/runtime"]
2122

2223
# Use a FIPS-validated version of boringssl.
2324
fips = ["tokio-boring/fips"]
@@ -28,16 +29,18 @@ fips-link-precompiled = ["tokio-boring/fips-link-precompiled"]
2829
# Enables experimental post-quantum crypto (https://blog.cloudflare.com/post-quantum-for-all/)
2930
pq-experimental = ["tokio-boring/pq-experimental"]
3031

31-
# Enable Hyper 1 support
32-
hyper1 = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:tower-service"]
32+
# Enable Hyper 0 support.
33+
hyper0 = ["dep:hyper0", "dep:http0"]
34+
# Enable Hyper 1 support.
35+
hyper1 = ["dep:http", "dep:hyper1", "dep:hyper-util", "dep:tower-service"]
3336

3437
[dependencies]
3538
antidote = { workspace = true }
3639
http = { workspace = true, optional = true }
37-
http_old = { workspace = true }
38-
hyper = { workspace = true, optional = true }
40+
http0 = { workspace = true, optional = true }
41+
hyper1 = { workspace = true, optional = true }
3942
hyper-util = { workspace = true, optional = true, features = ["client", "client-legacy"] }
40-
hyper_old = { workspace = true, features = ["client"] }
43+
hyper0 = { workspace = true, optional = true, features = ["client"] }
4144
linked_hash_set = { workspace = true }
4245
once_cell = { workspace = true }
4346
boring = { workspace = true }
@@ -50,8 +53,8 @@ tower-service = { workspace = true, optional = true }
5053
bytes = { workspace = true }
5154
http-body-util = { workspace = true }
5255
hyper-util = { workspace = true, features = ["http1", "http2", "service", "tokio"] }
53-
hyper = { workspace = true, features = ["server"] }
54-
hyper_old = { workspace = true, features = [ "full" ] }
56+
hyper1 = { workspace = true, features = ["server"] }
57+
hyper0 = { workspace = true, features = [ "full" ] }
5558
tokio = { workspace = true, features = [ "full" ] }
5659
tower = { workspace = true, features = ["util"] }
5760
futures = { workspace = true }

hyper-boring/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ use std::fmt;
1111
use tokio_boring::SslStream;
1212

1313
mod cache;
14+
#[cfg(all(feature = "hyper0", not(feature = "hyper1")))]
1415
mod v0;
16+
/// Hyper 0 support.
17+
#[cfg(all(feature = "hyper0", feature = "hyper1"))]
18+
pub mod v0;
19+
#[cfg(all(feature = "hyper1", not(feature = "hyper0")))]
20+
mod v1;
1521
/// Hyper 1 support.
16-
#[cfg(feature = "hyper1")]
22+
#[cfg(all(feature = "hyper1", feature = "hyper0"))]
1723
pub mod v1;
1824

25+
#[cfg(all(feature = "hyper0", not(feature = "hyper1")))]
1926
pub use self::v0::*;
27+
#[cfg(all(feature = "hyper1", not(feature = "hyper0")))]
28+
pub use self::v1::*;
2029

2130
fn key_index() -> Result<Index<Ssl, SessionKey>, ErrorStack> {
2231
static IDX: OnceCell<Index<Ssl, SessionKey>> = OnceCell::new();

hyper-boring/src/v0.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use boring::ssl::{
66
ConnectConfiguration, Ssl, SslConnector, SslConnectorBuilder, SslMethod, SslRef,
77
SslSessionCacheMode,
88
};
9-
use http_old::uri::Scheme;
10-
use hyper_old::client::connect::{Connected, Connection};
11-
use hyper_old::client::HttpConnector;
12-
use hyper_old::service::Service;
13-
use hyper_old::Uri;
9+
use http0::uri::Scheme;
10+
use hyper0::client::connect::{Connected, Connection};
11+
use hyper0::client::HttpConnector;
12+
use hyper0::service::Service;
13+
use hyper0::Uri;
1414
use std::error::Error;
1515
use std::future::Future;
1616
use std::net;

hyper-boring/src/v1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use boring::ssl::{
88
};
99
use http::uri::Scheme;
1010
use http::Uri;
11-
use hyper::rt::{Read, ReadBufCursor, Write};
11+
use hyper1::rt::{Read, ReadBufCursor, Write};
1212
use hyper_util::client::legacy::connect::{Connected, Connection, HttpConnector};
1313
use hyper_util::rt::TokioIo;
1414
use std::error::Error;

hyper-boring/tests/v0.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
#![cfg(feature = "hyper0")]
2+
13
use boring::ssl::{SslAcceptor, SslConnector, SslFiletype, SslMethod};
24
use futures::StreamExt;
5+
use hyper0::client::HttpConnector;
6+
use hyper0::server::conn::Http;
7+
use hyper0::{service, Response};
8+
use hyper0::{Body, Client};
9+
#[cfg(feature = "hyper1")]
10+
use hyper_boring::v0::HttpsConnector;
11+
#[cfg(not(feature = "hyper1"))]
312
use hyper_boring::HttpsConnector;
4-
use hyper_old::client::HttpConnector;
5-
use hyper_old::server::conn::Http;
6-
use hyper_old::{service, Response};
7-
use hyper_old::{Body, Client};
813
use std::convert::Infallible;
914
use std::{io, iter};
1015
use tokio::net::TcpListener;

hyper-boring/tests/v1.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use boring::ssl::{SslAcceptor, SslConnector, SslFiletype, SslMethod};
44
use bytes::Bytes;
55
use futures::StreamExt;
66
use http_body_util::{BodyStream, Empty};
7-
use hyper::{service, Response};
7+
use hyper1::{service, Response};
8+
#[cfg(feature = "hyper0")]
89
use hyper_boring::v1::HttpsConnector;
10+
#[cfg(not(feature = "hyper0"))]
11+
use hyper_boring::HttpsConnector;
912
use hyper_util::client::legacy::connect::HttpConnector;
1013
use hyper_util::client::legacy::Client;
1114
use hyper_util::rt::{TokioExecutor, TokioIo};
@@ -55,7 +58,7 @@ async fn localhost() {
5558
Ok::<_, io::Error>(Response::new(<Empty<Bytes>>::new()))
5659
});
5760

58-
hyper::server::conn::http1::Builder::new()
61+
hyper1::server::conn::http1::Builder::new()
5962
.keep_alive(false)
6063
.serve_connection(TokioIo::new(stream), service)
6164
.await
@@ -126,7 +129,7 @@ async fn alpn_h2() {
126129
Ok::<_, io::Error>(Response::new(<Empty<Bytes>>::new()))
127130
});
128131

129-
hyper::server::conn::http2::Builder::new(TokioExecutor::new())
132+
hyper1::server::conn::http2::Builder::new(TokioExecutor::new())
130133
.serve_connection(TokioIo::new(stream), service)
131134
.await
132135
.unwrap();

0 commit comments

Comments
 (0)