Revert "Refactor!: Remove strict `TokioIo` response requirement from `hyper_boring::v1::HttpsConnector`"
This reverts commit e518c2444a.
This commit is contained in:
parent
7b4bfcbbee
commit
f439f92564
|
|
@ -45,7 +45,7 @@ hyper-util = "0.1.6"
|
||||||
hyper_old = { package = "hyper", version = "0.14", default-features = false }
|
hyper_old = { package = "hyper", version = "0.14", default-features = false }
|
||||||
linked_hash_set = "0.1"
|
linked_hash_set = "0.1"
|
||||||
openssl-macros = "0.1.1"
|
openssl-macros = "0.1.1"
|
||||||
tower = { version = "0.4", default-features = false, features = ["util"] }
|
tower = "0.4"
|
||||||
tower-layer = "0.3"
|
tower-layer = "0.3"
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
autocfg = "1.3.0"
|
autocfg = "1.3.0"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
|
||||||
[features]
|
[features]
|
||||||
default = ["runtime"]
|
default = ["runtime"]
|
||||||
|
|
||||||
runtime = ["hyper_old/runtime", "dep:tower"]
|
runtime = ["hyper_old/runtime"]
|
||||||
|
|
||||||
# Use a FIPS-validated version of boringssl.
|
# Use a FIPS-validated version of boringssl.
|
||||||
fips = ["tokio-boring/fips"]
|
fips = ["tokio-boring/fips"]
|
||||||
|
|
@ -43,7 +43,6 @@ linked_hash_set = { workspace = true }
|
||||||
boring = { workspace = true }
|
boring = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
tokio-boring = { workspace = true }
|
tokio-boring = { workspace = true }
|
||||||
tower = { workspace = true, optional = true }
|
|
||||||
tower-layer = { workspace = true }
|
tower-layer = { workspace = true }
|
||||||
tower-service = { workspace = true, optional = true }
|
tower-service = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,6 @@ use std::sync::Arc;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::{io, net};
|
use std::{io, net};
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tokio::net::TcpStream;
|
|
||||||
#[cfg(feature = "runtime")]
|
|
||||||
use tower::util::MapResponse;
|
|
||||||
#[cfg(feature = "runtime")]
|
|
||||||
use tower::ServiceExt;
|
|
||||||
use tower_layer::Layer;
|
use tower_layer::Layer;
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
|
|
||||||
|
|
@ -34,30 +29,25 @@ pub struct HttpsConnector<T> {
|
||||||
inner: Inner,
|
inner: Inner,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specialized version of [`HttpConnector`] with responses wrapped with
|
|
||||||
/// [`TokioIo::new`] in order to bring back compatibility with Tokio traits.
|
|
||||||
pub type TokioHttpConnector =
|
|
||||||
MapResponse<HttpConnector, fn(TokioIo<TcpStream>) -> TokioIo<TokioIo<TcpStream>>>;
|
|
||||||
|
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
impl HttpsConnector<TokioHttpConnector> {
|
impl HttpsConnector<HttpConnector> {
|
||||||
/// Creates a a new `HttpsConnector` using default settings.
|
/// Creates a a new `HttpsConnector` using default settings.
|
||||||
///
|
///
|
||||||
/// The Hyper `HttpConnector` is used to perform the TCP socket connection. ALPN is configured to support both
|
/// The Hyper `HttpConnector` is used to perform the TCP socket connection. ALPN is configured to support both
|
||||||
/// HTTP/2 and HTTP/1.1.
|
/// HTTP/2 and HTTP/1.1.
|
||||||
///
|
///
|
||||||
/// Requires the `runtime` Cargo feature.
|
/// Requires the `runtime` Cargo feature.
|
||||||
pub fn new() -> Result<Self, ErrorStack> {
|
pub fn new() -> Result<HttpsConnector<HttpConnector>, ErrorStack> {
|
||||||
let mut http = HttpConnector::new();
|
let mut http = HttpConnector::new();
|
||||||
http.enforce_http(false);
|
http.enforce_http(false);
|
||||||
|
|
||||||
HttpsLayer::new().map(|l| l.layer(http.map_response(TokioIo::new as _)))
|
HttpsLayer::new().map(|l| l.layer(http))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T> HttpsConnector<S>
|
impl<S, T> HttpsConnector<S>
|
||||||
where
|
where
|
||||||
S: Service<Uri, Response = T> + Send,
|
S: Service<Uri, Response = TokioIo<T>> + Send,
|
||||||
S::Error: Into<Box<dyn Error + Send + Sync>>,
|
S::Error: Into<Box<dyn Error + Send + Sync>>,
|
||||||
S::Future: Unpin + Send + 'static,
|
S::Future: Unpin + Send + 'static,
|
||||||
T: AsyncRead + AsyncWrite + Connection + Unpin + fmt::Debug + Sync + Send + 'static,
|
T: AsyncRead + AsyncWrite + Connection + Unpin + fmt::Debug + Sync + Send + 'static,
|
||||||
|
|
@ -65,10 +55,6 @@ where
|
||||||
/// Creates a new `HttpsConnector`.
|
/// Creates a new `HttpsConnector`.
|
||||||
///
|
///
|
||||||
/// The session cache configuration of `ssl` will be overwritten.
|
/// The session cache configuration of `ssl` will be overwritten.
|
||||||
///
|
|
||||||
/// If the provided service's response type does not fit the trait
|
|
||||||
/// requirements because it is closer to the Hyper ecosystem than the Tokio
|
|
||||||
/// one, wrapping your responses with [`TokioIo`] should work.
|
|
||||||
pub fn with_connector(
|
pub fn with_connector(
|
||||||
http: S,
|
http: S,
|
||||||
ssl: SslConnectorBuilder,
|
ssl: SslConnectorBuilder,
|
||||||
|
|
@ -229,7 +215,7 @@ impl Inner {
|
||||||
|
|
||||||
impl<T, S> Service<Uri> for HttpsConnector<S>
|
impl<T, S> Service<Uri> for HttpsConnector<S>
|
||||||
where
|
where
|
||||||
S: Service<Uri, Response = T> + Send,
|
S: Service<Uri, Response = TokioIo<T>> + Send,
|
||||||
S::Error: Into<Box<dyn Error + Send + Sync>>,
|
S::Error: Into<Box<dyn Error + Send + Sync>>,
|
||||||
S::Future: Unpin + Send + 'static,
|
S::Future: Unpin + Send + 'static,
|
||||||
T: AsyncRead + AsyncWrite + Connection + Unpin + fmt::Debug + Sync + Send + 'static,
|
T: AsyncRead + AsyncWrite + Connection + Unpin + fmt::Debug + Sync + Send + 'static,
|
||||||
|
|
@ -258,7 +244,7 @@ where
|
||||||
let connect = self.http.call(uri);
|
let connect = self.http.call(uri);
|
||||||
|
|
||||||
let f = async {
|
let f = async {
|
||||||
let conn = connect.await.map_err(Into::into)?;
|
let conn = connect.await.map_err(Into::into)?.into_inner();
|
||||||
|
|
||||||
let (inner, uri) = match tls_setup {
|
let (inner, uri) = match tls_setup {
|
||||||
Some((inner, uri)) => (inner, uri),
|
Some((inner, uri)) => (inner, uri),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ use hyper_util::rt::{TokioExecutor, TokioIo};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::{io, iter};
|
use std::{io, iter};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tower::ServiceExt;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn google() {
|
async fn google() {
|
||||||
|
|
@ -84,7 +83,7 @@ async fn localhost() {
|
||||||
let _ = writeln!(&file, "{}", line);
|
let _ = writeln!(&file, "{}", line);
|
||||||
});
|
});
|
||||||
|
|
||||||
let ssl = HttpsConnector::with_connector(connector.map_response(TokioIo::new), ssl).unwrap();
|
let ssl = HttpsConnector::with_connector(connector, ssl).unwrap();
|
||||||
let client = Client::builder(TokioExecutor::new()).build::<_, Empty<Bytes>>(ssl);
|
let client = Client::builder(TokioExecutor::new()).build::<_, Empty<Bytes>>(ssl);
|
||||||
|
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
|
|
@ -145,8 +144,7 @@ async fn alpn_h2() {
|
||||||
|
|
||||||
ssl.set_ca_file("tests/test/root-ca.pem").unwrap();
|
ssl.set_ca_file("tests/test/root-ca.pem").unwrap();
|
||||||
|
|
||||||
let mut ssl =
|
let mut ssl = HttpsConnector::with_connector(connector, ssl).unwrap();
|
||||||
HttpsConnector::with_connector(connector.map_response(TokioIo::new), ssl).unwrap();
|
|
||||||
|
|
||||||
ssl.set_ssl_callback(|ssl, _| ssl.set_alpn_protos(b"\x02h2\x08http/1.1"));
|
ssl.set_ssl_callback(|ssl, _| ssl.set_alpn_protos(b"\x02h2\x08http/1.1"));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue