Skip to content

Commit 49d5a61

Browse files
PaulDancekornelski
authored andcommitted
Refactor!: Introduce a Cargo feature for optional Hyper 0 support
Closes #294. Requires breaking changes. The default v0 is changed in favor of v1, but v0 is still kept available, just in a forced module path. It enables dependency de-duplication when consuming it. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
1 parent e518c24 commit 49d5a61

File tree

8 files changed

+51
-39
lines changed

8 files changed

+51
-39
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
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 hyper1
369+
- run: cargo test -p hyper-boring --features hyper1-runtime
370370
name: Run hyper 1.0 tests for hyper-boring
371+
- run: cargo test -p hyper-boring --features hyper0-runtime
372+
name: Run hyper 0. tests for hyper-boring

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ futures = "0.3"
3737
tokio = "1"
3838
anyhow = "1"
3939
antidote = "1.0.0"
40-
http = "1"
40+
http1 = { package = "http", version = "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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ features = ["pq-experimental"]
1515
rustdoc-args = ["--cfg", "docsrs"]
1616

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

20-
runtime = ["hyper_old/runtime", "dep:tower"]
20+
runtime = []
21+
# `hyper1` + `runtime`.
22+
hyper1-runtime = ["hyper1", "dep:tower"]
23+
# `hyper0` + `runtime`.
24+
hyper0-runtime = ["hyper0", "hyper0/runtime"]
2125

2226
# Use a FIPS-validated version of boringssl.
2327
fips = ["tokio-boring/fips"]
@@ -28,16 +32,18 @@ fips-link-precompiled = ["tokio-boring/fips-link-precompiled"]
2832
# Enables experimental post-quantum crypto (https://blog.cloudflare.com/post-quantum-for-all/)
2933
pq-experimental = ["tokio-boring/pq-experimental"]
3034

31-
# Enable Hyper 1 support
32-
hyper1 = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:tower-service"]
35+
# Enable Hyper 1 support.
36+
hyper1 = ["dep:hyper1", "dep:http1", "dep:hyper-util", "dep:tower-service"]
37+
# Enable Hyper 0 support.
38+
hyper0 = ["dep:hyper0", "dep:http0"]
3339

3440
[dependencies]
3541
antidote = { workspace = true }
36-
http = { workspace = true, optional = true }
37-
http_old = { workspace = true }
38-
hyper = { workspace = true, optional = true }
42+
http1 = { workspace = true, optional = true }
43+
http0 = { workspace = true, optional = true }
44+
hyper1 = { workspace = true, optional = true }
3945
hyper-util = { workspace = true, optional = true, features = ["client", "client-legacy"] }
40-
hyper_old = { workspace = true, features = ["client"] }
46+
hyper0 = { workspace = true, optional = true, features = ["client"] }
4147
linked_hash_set = { workspace = true }
4248
once_cell = { workspace = true }
4349
boring = { workspace = true }
@@ -51,8 +57,8 @@ tower-service = { workspace = true, optional = true }
5157
bytes = { workspace = true }
5258
http-body-util = { workspace = true }
5359
hyper-util = { workspace = true, features = ["http1", "http2", "service", "tokio"] }
54-
hyper = { workspace = true, features = ["server"] }
55-
hyper_old = { workspace = true, features = [ "full" ] }
60+
hyper1 = { workspace = true, features = ["server"] }
61+
hyper0 = { workspace = true, features = [ "full" ] }
5662
tokio = { workspace = true, features = [ "full" ] }
5763
tower = { workspace = true, features = ["util"] }
5864
futures = { workspace = true }

hyper-boring/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ use std::fmt;
1111
use tokio_boring::SslStream;
1212

1313
mod cache;
14-
mod v0;
15-
/// Hyper 1 support.
14+
/// Hyper 0 support.
15+
#[cfg(feature = "hyper0")]
16+
pub mod v0;
1617
#[cfg(feature = "hyper1")]
17-
pub mod v1;
18+
mod v1;
1819

19-
pub use self::v0::*;
20+
#[cfg(feature = "hyper1")]
21+
pub use self::v1::*;
2022

2123
fn key_index() -> Result<Index<Ssl, SessionKey>, ErrorStack> {
2224
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use boring::ssl::{
66
ConnectConfiguration, Ssl, SslConnector, SslConnectorBuilder, SslMethod, SslRef,
77
SslSessionCacheMode,
88
};
9-
use http::uri::Scheme;
10-
use http::Uri;
11-
use hyper::rt::{Read, ReadBufCursor, Write};
9+
use http1::uri::Scheme;
10+
use http1::Uri;
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;
@@ -20,9 +20,9 @@ use std::task::{Context, Poll};
2020
use std::{io, net};
2121
use tokio::io::{AsyncRead, AsyncWrite};
2222
use tokio::net::TcpStream;
23-
#[cfg(feature = "runtime")]
23+
#[cfg(all(feature = "runtime", feature = "hyper1-runtime"))]
2424
use tower::util::MapResponse;
25-
#[cfg(feature = "runtime")]
25+
#[cfg(all(feature = "runtime", feature = "hyper1-runtime"))]
2626
use tower::ServiceExt;
2727
use tower_layer::Layer;
2828
use tower_service::Service;
@@ -39,7 +39,7 @@ pub struct HttpsConnector<T> {
3939
pub type TokioHttpConnector =
4040
MapResponse<HttpConnector, fn(TokioIo<TcpStream>) -> TokioIo<TokioIo<TcpStream>>>;
4141

42-
#[cfg(feature = "runtime")]
42+
#[cfg(all(feature = "runtime", feature = "hyper1-runtime"))]
4343
impl HttpsConnector<TokioHttpConnector> {
4444
/// Creates a a new `HttpsConnector` using default settings.
4545
///

hyper-boring/tests/v0.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
#![cfg(feature = "hyper0")]
2+
13
use boring::ssl::{SslAcceptor, SslConnector, SslFiletype, SslMethod};
24
use futures::StreamExt;
3-
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};
5+
use hyper0::client::HttpConnector;
6+
use hyper0::server::conn::Http;
7+
use hyper0::{service, Response};
8+
use hyper0::{Body, Client};
9+
use hyper_boring::v0::HttpsConnector;
810
use std::convert::Infallible;
911
use std::{io, iter};
1012
use tokio::net::TcpListener;

hyper-boring/tests/v1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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};
8-
use hyper_boring::v1::HttpsConnector;
7+
use hyper1::{service, Response};
8+
use hyper_boring::HttpsConnector;
99
use hyper_util::client::legacy::connect::HttpConnector;
1010
use hyper_util::client::legacy::Client;
1111
use hyper_util::rt::{TokioExecutor, TokioIo};
@@ -56,7 +56,7 @@ async fn localhost() {
5656
Ok::<_, io::Error>(Response::new(<Empty<Bytes>>::new()))
5757
});
5858

59-
hyper::server::conn::http1::Builder::new()
59+
hyper1::server::conn::http1::Builder::new()
6060
.keep_alive(false)
6161
.serve_connection(TokioIo::new(stream), service)
6262
.await
@@ -127,7 +127,7 @@ async fn alpn_h2() {
127127
Ok::<_, io::Error>(Response::new(<Empty<Bytes>>::new()))
128128
});
129129

130-
hyper::server::conn::http2::Builder::new(TokioExecutor::new())
130+
hyper1::server::conn::http2::Builder::new(TokioExecutor::new())
131131
.serve_connection(TokioIo::new(stream), service)
132132
.await
133133
.unwrap();

0 commit comments

Comments
 (0)