Skip to content

Commit

Permalink
Refactor!: Introduce a Cargo feature for optional Hyper 0 support
Browse files Browse the repository at this point in the history
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 <paul.mabileau@harfanglab.fr>
  • Loading branch information
PaulDance committed Dec 6, 2024
1 parent 4685af0 commit 55d3e32
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,7 @@ jobs:
name: Run `rpk,underscore-wildcards` tests
- run: cargo test --features pq-experimental,rpk,underscore-wildcards
name: Run `pq-experimental,rpk,underscore-wildcards` tests
- run: cargo test -p hyper-boring --features hyper0
name: Run hyper 0. tests for hyper-boring
- run: cargo test -p hyper-boring --features hyper1
name: Run hyper 1.0 tests for hyper-boring
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ anyhow = "1"
antidote = "1.0.0"
http = "1"
http-body-util = "0.1.2"
http_old = { package = "http", version = "0.2" }
hyper = "1"
http0 = { package = "http", version = "0.2" }
hyper1 = { package = "hyper", version = "1" }
hyper-util = "0.1.6"
hyper_old = { package = "hyper", version = "0.14", default-features = false }
hyper0 = { package = "hyper", version = "0.14", default-features = false }
linked_hash_set = "0.1"
once_cell = "1.0"
openssl-macros = "0.1.1"
Expand Down
21 changes: 12 additions & 9 deletions hyper-boring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ features = ["pq-experimental"]
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["runtime"]
default = ["runtime", "hyper0-runtime"]

runtime = ["hyper_old/runtime"]
runtime = []
hyper0-runtime = ["hyper0", "hyper0/runtime"]

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

# Enable Hyper 1 support
hyper1 = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:tower-service"]
# Enable Hyper 0 support.
hyper0 = ["dep:hyper0", "dep:http0"]
# Enable Hyper 1 support.
hyper1 = ["dep:http", "dep:hyper1", "dep:hyper-util", "dep:tower-service"]

[dependencies]
antidote = { workspace = true }
http = { workspace = true, optional = true }
http_old = { workspace = true }
hyper = { workspace = true, optional = true }
http0 = { workspace = true, optional = true }
hyper1 = { workspace = true, optional = true }
hyper-util = { workspace = true, optional = true, features = ["client", "client-legacy"] }
hyper_old = { workspace = true, features = ["client"] }
hyper0 = { workspace = true, optional = true, features = ["client"] }
linked_hash_set = { workspace = true }
once_cell = { workspace = true }
boring = { workspace = true }
Expand All @@ -50,8 +53,8 @@ tower-service = { workspace = true, optional = true }
bytes = { workspace = true }
http-body-util = { workspace = true }
hyper-util = { workspace = true, features = ["http1", "http2", "service", "tokio"] }
hyper = { workspace = true, features = ["server"] }
hyper_old = { workspace = true, features = [ "full" ] }
hyper1 = { workspace = true, features = ["server"] }
hyper0 = { workspace = true, features = [ "full" ] }
tokio = { workspace = true, features = [ "full" ] }
tower = { workspace = true, features = ["util"] }
futures = { workspace = true }
Expand Down
11 changes: 10 additions & 1 deletion hyper-boring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ use std::fmt;
use tokio_boring::SslStream;

mod cache;
#[cfg(all(feature = "hyper0", not(feature = "hyper1")))]
mod v0;
/// Hyper 0 support.
#[cfg(all(feature = "hyper0", feature = "hyper1"))]
pub mod v0;
#[cfg(all(feature = "hyper1", not(feature = "hyper0")))]
mod v1;
/// Hyper 1 support.
#[cfg(feature = "hyper1")]
#[cfg(all(feature = "hyper1", feature = "hyper0"))]
pub mod v1;

#[cfg(all(feature = "hyper0", not(feature = "hyper1")))]
pub use self::v0::*;
#[cfg(all(feature = "hyper1", not(feature = "hyper0")))]
pub use self::v1::*;

fn key_index() -> Result<Index<Ssl, SessionKey>, ErrorStack> {
static IDX: OnceCell<Index<Ssl, SessionKey>> = OnceCell::new();
Expand Down
10 changes: 5 additions & 5 deletions hyper-boring/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use boring::ssl::{
ConnectConfiguration, Ssl, SslConnector, SslConnectorBuilder, SslMethod, SslRef,
SslSessionCacheMode,
};
use http_old::uri::Scheme;
use hyper_old::client::connect::{Connected, Connection};
use hyper_old::client::HttpConnector;
use hyper_old::service::Service;
use hyper_old::Uri;
use http0::uri::Scheme;
use hyper0::client::connect::{Connected, Connection};
use hyper0::client::HttpConnector;
use hyper0::service::Service;
use hyper0::Uri;
use std::error::Error;
use std::future::Future;
use std::net;
Expand Down
2 changes: 1 addition & 1 deletion hyper-boring/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use boring::ssl::{
};
use http::uri::Scheme;
use http::Uri;
use hyper::rt::{Read, ReadBufCursor, Write};
use hyper1::rt::{Read, ReadBufCursor, Write};
use hyper_util::client::legacy::connect::{Connected, Connection, HttpConnector};
use hyper_util::rt::TokioIo;
use std::error::Error;
Expand Down
13 changes: 9 additions & 4 deletions hyper-boring/tests/v0.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#![cfg(feature = "hyper0")]

use boring::ssl::{SslAcceptor, SslConnector, SslFiletype, SslMethod};
use futures::StreamExt;
use hyper0::client::HttpConnector;
use hyper0::server::conn::Http;
use hyper0::{service, Response};
use hyper0::{Body, Client};
#[cfg(feature = "hyper1")]
use hyper_boring::v0::HttpsConnector;
#[cfg(not(feature = "hyper1"))]
use hyper_boring::HttpsConnector;
use hyper_old::client::HttpConnector;
use hyper_old::server::conn::Http;
use hyper_old::{service, Response};
use hyper_old::{Body, Client};
use std::convert::Infallible;
use std::{io, iter};
use tokio::net::TcpListener;
Expand Down
9 changes: 6 additions & 3 deletions hyper-boring/tests/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use boring::ssl::{SslAcceptor, SslConnector, SslFiletype, SslMethod};
use bytes::Bytes;
use futures::StreamExt;
use http_body_util::{BodyStream, Empty};
use hyper::{service, Response};
use hyper1::{service, Response};
#[cfg(feature = "hyper0")]
use hyper_boring::v1::HttpsConnector;
#[cfg(not(feature = "hyper0"))]
use hyper_boring::HttpsConnector;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::client::legacy::Client;
use hyper_util::rt::{TokioExecutor, TokioIo};
Expand Down Expand Up @@ -55,7 +58,7 @@ async fn localhost() {
Ok::<_, io::Error>(Response::new(<Empty<Bytes>>::new()))
});

hyper::server::conn::http1::Builder::new()
hyper1::server::conn::http1::Builder::new()
.keep_alive(false)
.serve_connection(TokioIo::new(stream), service)
.await
Expand Down Expand Up @@ -126,7 +129,7 @@ async fn alpn_h2() {
Ok::<_, io::Error>(Response::new(<Empty<Bytes>>::new()))
});

hyper::server::conn::http2::Builder::new(TokioExecutor::new())
hyper1::server::conn::http2::Builder::new(TokioExecutor::new())
.serve_connection(TokioIo::new(stream), service)
.await
.unwrap();
Expand Down

0 comments on commit 55d3e32

Please sign in to comment.