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 }
|
||||
linked_hash_set = "0.1"
|
||||
openssl-macros = "0.1.1"
|
||||
tower = { version = "0.4", default-features = false, features = ["util"] }
|
||||
tower = "0.4"
|
||||
tower-layer = "0.3"
|
||||
tower-service = "0.3"
|
||||
autocfg = "1.3.0"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||
[features]
|
||||
default = ["runtime"]
|
||||
|
||||
runtime = ["hyper_old/runtime", "dep:tower"]
|
||||
runtime = ["hyper_old/runtime"]
|
||||
|
||||
# Use a FIPS-validated version of boringssl.
|
||||
fips = ["tokio-boring/fips"]
|
||||
|
|
@ -43,7 +43,6 @@ linked_hash_set = { workspace = true }
|
|||
boring = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tokio-boring = { workspace = true }
|
||||
tower = { workspace = true, optional = true }
|
||||
tower-layer = { workspace = true }
|
||||
tower-service = { workspace = true, optional = true }
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,6 @@ use std::sync::Arc;
|
|||
use std::task::{Context, Poll};
|
||||
use std::{io, net};
|
||||
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_service::Service;
|
||||
|
||||
|
|
@ -34,30 +29,25 @@ pub struct HttpsConnector<T> {
|
|||
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")]
|
||||
impl HttpsConnector<TokioHttpConnector> {
|
||||
impl HttpsConnector<HttpConnector> {
|
||||
/// 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
|
||||
/// HTTP/2 and HTTP/1.1.
|
||||
///
|
||||
/// Requires the `runtime` Cargo feature.
|
||||
pub fn new() -> Result<Self, ErrorStack> {
|
||||
pub fn new() -> Result<HttpsConnector<HttpConnector>, ErrorStack> {
|
||||
let mut http = HttpConnector::new();
|
||||
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>
|
||||
where
|
||||
S: Service<Uri, Response = T> + Send,
|
||||
S: Service<Uri, Response = TokioIo<T>> + Send,
|
||||
S::Error: Into<Box<dyn Error + Send + Sync>>,
|
||||
S::Future: Unpin + Send + 'static,
|
||||
T: AsyncRead + AsyncWrite + Connection + Unpin + fmt::Debug + Sync + Send + 'static,
|
||||
|
|
@ -65,10 +55,6 @@ where
|
|||
/// Creates a new `HttpsConnector`.
|
||||
///
|
||||
/// 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(
|
||||
http: S,
|
||||
ssl: SslConnectorBuilder,
|
||||
|
|
@ -229,7 +215,7 @@ impl Inner {
|
|||
|
||||
impl<T, S> Service<Uri> for HttpsConnector<S>
|
||||
where
|
||||
S: Service<Uri, Response = T> + Send,
|
||||
S: Service<Uri, Response = TokioIo<T>> + Send,
|
||||
S::Error: Into<Box<dyn Error + Send + Sync>>,
|
||||
S::Future: Unpin + Send + 'static,
|
||||
T: AsyncRead + AsyncWrite + Connection + Unpin + fmt::Debug + Sync + Send + 'static,
|
||||
|
|
@ -258,7 +244,7 @@ where
|
|||
let connect = self.http.call(uri);
|
||||
|
||||
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 {
|
||||
Some((inner, uri)) => (inner, uri),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use hyper_util::rt::{TokioExecutor, TokioIo};
|
|||
use std::convert::Infallible;
|
||||
use std::{io, iter};
|
||||
use tokio::net::TcpListener;
|
||||
use tower::ServiceExt;
|
||||
|
||||
#[tokio::test]
|
||||
async fn google() {
|
||||
|
|
@ -84,7 +83,7 @@ async fn localhost() {
|
|||
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);
|
||||
|
||||
for _ in 0..3 {
|
||||
|
|
@ -145,8 +144,7 @@ async fn alpn_h2() {
|
|||
|
||||
ssl.set_ca_file("tests/test/root-ca.pem").unwrap();
|
||||
|
||||
let mut ssl =
|
||||
HttpsConnector::with_connector(connector.map_response(TokioIo::new), ssl).unwrap();
|
||||
let mut ssl = HttpsConnector::with_connector(connector, ssl).unwrap();
|
||||
|
||||
ssl.set_ssl_callback(|ssl, _| ssl.set_alpn_protos(b"\x02h2\x08http/1.1"));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue