From b036ec8ea25195acc7da9030c959de418a5358ca Mon Sep 17 00:00:00 2001 From: Sergei Gureev Date: Mon, 12 Jul 2021 11:38:04 +0300 Subject: [PATCH 1/6] Update deadpool to 0.8.1 --- Cargo.toml | 2 +- src/h1/mod.rs | 27 +++++++-------------------- src/h1/tcp.rs | 8 +++++--- src/h1/tls.rs | 8 +++++--- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4931c39..2b2e1bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ cfg-if = "1.0.0" async-h1 = { version = "2.0.0", optional = true } async-std = { version = "1.6.0", default-features = false, optional = true } async-native-tls = { version = "0.3.1", optional = true } -deadpool = { version = "0.7.0", optional = true } +deadpool = { version = "0.8.1", optional = true } futures = { version = "0.3.8", optional = true } # h1_client_rustls diff --git a/src/h1/mod.rs b/src/h1/mod.rs index 6577732..8076394 100644 --- a/src/h1/mod.rs +++ b/src/h1/mod.rs @@ -8,19 +8,10 @@ use std::net::SocketAddr; use std::sync::Arc; use async_h1::client; -use async_std::net::TcpStream; use dashmap::DashMap; use deadpool::managed::Pool; use http_types::StatusCode; -cfg_if::cfg_if! { - if #[cfg(feature = "rustls")] { - use async_tls::client::TlsStream; - } else if #[cfg(feature = "native-tls")] { - use async_native_tls::TlsStream; - } -} - use crate::Config; use super::{async_trait, Error, HttpClient, Request, Response}; @@ -36,11 +27,11 @@ use tls::{TlsConnWrapper, TlsConnection}; // This number is based on a few random benchmarks and see whatever gave decent perf vs resource use. const DEFAULT_MAX_CONCURRENT_CONNECTIONS: usize = 50; -type HttpPool = DashMap>; +type HttpPool = DashMap>; #[cfg(any(feature = "native-tls", feature = "rustls"))] -type HttpsPool = DashMap, Error>>; +type HttpsPool = DashMap>; -/// Async-h1 based HTTP Client, with connecton pooling ("Keep-Alive"). +/// Async-h1 based HTTP Client, with connection pooling ("Keep-Alive"). pub struct H1Client { http_pools: HttpPool, #[cfg(any(feature = "native-tls", feature = "rustls"))] @@ -194,10 +185,8 @@ impl HttpClient for H1Client { pool_ref } else { let manager = TcpConnection::new(addr, self.config.clone()); - let pool = Pool::::new( - manager, - self.max_concurrent_connections, - ); + let pool = + Pool::::new(manager, self.max_concurrent_connections); self.http_pools.insert(addr, pool); self.http_pools.get(&addr).unwrap() }; @@ -231,10 +220,8 @@ impl HttpClient for H1Client { pool_ref } else { let manager = TlsConnection::new(host.clone(), addr, self.config.clone()); - let pool = Pool::, Error>::new( - manager, - self.max_concurrent_connections, - ); + let pool = + Pool::::new(manager, self.max_concurrent_connections); self.https_pools.insert(addr, pool); self.https_pools.get(&addr).unwrap() }; diff --git a/src/h1/tcp.rs b/src/h1/tcp.rs index 6b855fd..394491a 100644 --- a/src/h1/tcp.rs +++ b/src/h1/tcp.rs @@ -24,10 +24,10 @@ impl TcpConnection { } pub(crate) struct TcpConnWrapper { - conn: Object, + conn: Object, } impl TcpConnWrapper { - pub(crate) fn new(conn: Object) -> Self { + pub(crate) fn new(conn: Object) -> Self { Self { conn } } } @@ -61,7 +61,9 @@ impl AsyncWrite for TcpConnWrapper { } #[async_trait] -impl Manager for TcpConnection { +impl Manager for TcpConnection { + type Type = TcpStream; + type Error = std::io::Error; async fn create(&self) -> Result { let tcp_stream = TcpStream::connect(self.addr).await?; diff --git a/src/h1/tls.rs b/src/h1/tls.rs index 796936c..eb1b0f9 100644 --- a/src/h1/tls.rs +++ b/src/h1/tls.rs @@ -33,10 +33,10 @@ impl TlsConnection { } pub(crate) struct TlsConnWrapper { - conn: Object, Error>, + conn: Object, } impl TlsConnWrapper { - pub(crate) fn new(conn: Object, Error>) -> Self { + pub(crate) fn new(conn: Object) -> Self { Self { conn } } } @@ -70,7 +70,9 @@ impl AsyncWrite for TlsConnWrapper { } #[async_trait] -impl Manager, Error> for TlsConnection { +impl Manager for TlsConnection { + type Type = TlsStream; + type Error = Error; async fn create(&self) -> Result, Error> { let raw_stream = async_std::net::TcpStream::connect(self.addr).await?; From 2aeba959760adbae90e8d06fd61d751ea84729a8 Mon Sep 17 00:00:00 2001 From: Sergei Gureev Date: Mon, 12 Jul 2021 12:24:15 +0300 Subject: [PATCH 2/6] Update hyper to 0.14 And most of the other libs --- Cargo.toml | 18 +++++++++--------- src/hyper.rs | 6 ++++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2b2e1bb..4a8db08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,14 +49,14 @@ deadpool = { version = "0.8.1", optional = true } futures = { version = "0.3.8", optional = true } # h1_client_rustls -async-tls = { version = "0.10.0", optional = true } -rustls_crate = { version = "0.18", optional = true, package = "rustls" } +async-tls = { version = "0.11.0", optional = true } +rustls_crate = { version = "0.19.1", optional = true, package = "rustls" } # hyper_client -hyper = { version = "0.13.6", features = ["tcp"], optional = true } -hyper-tls = { version = "0.4.3", optional = true } +hyper = { version = "0.14.10", features = ["tcp", "client", "server", "http2", "stream"], optional = true } +hyper-tls = { version = "0.5.0", optional = true } futures-util = { version = "0.3.5", features = ["io"], optional = true } -tokio = { version = "0.2", features = ["time"], optional = true } +tokio = { version = "1.8.1", features = ["time", "io-util"], optional = true } # curl_client [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -91,12 +91,12 @@ features = [ [dev-dependencies] async-std = { version = "1.6.0", features = ["unstable", "attributes"] } portpicker = "0.1.0" -tide = { version = "0.15.0", default-features = false, features = ["h1-server"] } -tide-rustls = { version = "0.1.4" } -tokio = { version = "0.2.21", features = ["macros"] } +tide = { version = "0.16.0", default-features = false, features = ["h1-server"] } +tide-rustls = { version = "0.3.0" } +tokio = { version = "1.8.1", features = ["macros"] } serde = "1.0" serde_json = "1.0" -mockito = "0.23.3" +mockito = "0.30.0" [dev-dependencies.getrandom] version = "0.2" diff --git a/src/hyper.rs b/src/hyper.rs index c1404fc..2c04583 100644 --- a/src/hyper.rs +++ b/src/hyper.rs @@ -192,7 +192,9 @@ impl HttpTypesResponse { let (parts, body) = value.into_parts(); let size_hint = body.size_hint().upper().map(|s| s as usize); - let body = body.map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string())); + let body = TryStreamExt::map_err(body, |err| { + io::Error::new(io::ErrorKind::Other, err.to_string()) + }); let body = http_types::Body::from_reader(body.into_async_read(), size_hint); let mut res = Response::new(parts.status); @@ -252,7 +254,7 @@ mod tests { req.set_body("hello"); let client = async move { - tokio::time::delay_for(Duration::from_millis(100)).await; + tokio::time::sleep(Duration::from_millis(100)).await; let mut resp = client.send(req).await?; send.send(()).unwrap(); assert_eq!(resp.body_string().await?, "hello"); From b0ce7aad0daf136c866ec8de813bda0e8301c935 Mon Sep 17 00:00:00 2001 From: Sergei Gureev Date: Mon, 12 Jul 2021 12:31:49 +0300 Subject: [PATCH 3/6] Update isahc to 1.4.0 --- Cargo.toml | 2 +- src/isahc.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a8db08..75fa8e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ tokio = { version = "1.8.1", features = ["time", "io-util"], optional = true } # curl_client [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -isahc = { version = "0.9", optional = true, default-features = false, features = ["http2"] } +isahc = { version = "1.4.0", optional = true, default-features = false, features = ["http2"] } # wasm_client [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/src/isahc.rs b/src/isahc.rs index 30afdc1..4482aae 100644 --- a/src/isahc.rs +++ b/src/isahc.rs @@ -53,8 +53,8 @@ impl HttpClient for IsahcClient { let body = req.take_body(); let body = match body.len() { - Some(len) => isahc::Body::from_reader_sized(body, len as u64), - None => isahc::Body::from_reader(body), + Some(len) => isahc::AsyncBody::from_reader_sized(body, len as u64), + None => isahc::AsyncBody::from_reader(body), }; let request = builder.body(body).unwrap(); From 890a9b742d2fe6861e8c659f822f3bf4ee3846b3 Mon Sep 17 00:00:00 2001 From: Sergei Gureev Date: Mon, 12 Jul 2021 12:33:47 +0300 Subject: [PATCH 4/6] Run cargo-diet --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 75fa8e0..6e67c39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ authors = [ ] readme = "README.md" edition = "2018" +include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"] [package.metadata.docs.rs] features = ["docs"] From 959895c2c6335e028392576b955561e23b552aa3 Mon Sep 17 00:00:00 2001 From: Sergei Gureev Date: Mon, 12 Jul 2021 19:40:42 +0300 Subject: [PATCH 5/6] Update the rest of the deps --- Cargo.toml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e67c39..8275a1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,18 +36,18 @@ rustls = ["async-tls", "rustls_crate"] unstable-config = [] [dependencies] -async-trait = "0.1.37" +async-trait = "0.1.50" dashmap = "4.0.2" -http-types = "2.3.0" -log = "0.4.7" +http-types = "2.11.1" +log = "0.4.14" cfg-if = "1.0.0" # h1_client -async-h1 = { version = "2.0.0", optional = true } -async-std = { version = "1.6.0", default-features = false, optional = true } -async-native-tls = { version = "0.3.1", optional = true } +async-h1 = { version = "2.3.2", optional = true } +async-std = { version = "1.9.0", default-features = false, optional = true } +async-native-tls = { version = "0.3.*", optional = true } deadpool = { version = "0.8.1", optional = true } -futures = { version = "0.3.8", optional = true } +futures = { version = "0.3.15", optional = true } # h1_client_rustls async-tls = { version = "0.11.0", optional = true } @@ -56,22 +56,22 @@ rustls_crate = { version = "0.19.1", optional = true, package = "rustls" } # hyper_client hyper = { version = "0.14.10", features = ["tcp", "client", "server", "http2", "stream"], optional = true } hyper-tls = { version = "0.5.0", optional = true } -futures-util = { version = "0.3.5", features = ["io"], optional = true } +futures-util = { version = "0.3.15", features = ["io"], optional = true } tokio = { version = "1.8.1", features = ["time", "io-util"], optional = true } # curl_client [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -isahc = { version = "1.4.0", optional = true, default-features = false, features = ["http2"] } +isahc = { version = "1.4.0", optional = true, default-features = false, features = ["http2"] } # wasm_client [target.'cfg(target_arch = "wasm32")'.dependencies] -js-sys = { version = "0.3.25", optional = true } -wasm-bindgen = { version = "0.2.48", optional = true } -wasm-bindgen-futures = { version = "0.4.5", optional = true } -futures = { version = "0.3.1", optional = true } +js-sys = { version = "0.3.51", optional = true } +wasm-bindgen = { version = "0.2.74", optional = true } +wasm-bindgen-futures = { version = "0.4.24", optional = true } +futures = { version = "0.3.15", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies.web-sys] -version = "0.3.25" +version = "0.3.51" optional = true features = [ "AbortSignal", @@ -90,15 +90,15 @@ features = [ ] [dev-dependencies] -async-std = { version = "1.6.0", features = ["unstable", "attributes"] } -portpicker = "0.1.0" +async-std = { version = "1.9.0", features = ["unstable", "attributes"] } +portpicker = "0.1.1" tide = { version = "0.16.0", default-features = false, features = ["h1-server"] } -tide-rustls = { version = "0.3.0" } +tide-rustls = "0.3.0" tokio = { version = "1.8.1", features = ["macros"] } -serde = "1.0" -serde_json = "1.0" +serde = "1.0.126" +serde_json = "1.0.64" mockito = "0.30.0" [dev-dependencies.getrandom] -version = "0.2" +version = "0.2.3" features = ["js"] From 1bf749635d185c661bc3405417dbfa622900ed81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=AD?= Date: Fri, 16 Jul 2021 10:17:06 +0300 Subject: [PATCH 6/6] Move dev features to dev-deps --- Cargo.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8275a1f..ebd0346 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,13 +51,13 @@ futures = { version = "0.3.15", optional = true } # h1_client_rustls async-tls = { version = "0.11.0", optional = true } -rustls_crate = { version = "0.19.1", optional = true, package = "rustls" } +rustls_crate = { version = "0.19.*", optional = true, package = "rustls" } # hyper_client -hyper = { version = "0.14.10", features = ["tcp", "client", "server", "http2", "stream"], optional = true } +hyper = { version = "0.14.10", features = ["tcp", "client", "http1", "http2", "stream"], optional = true } hyper-tls = { version = "0.5.0", optional = true } futures-util = { version = "0.3.15", features = ["io"], optional = true } -tokio = { version = "1.8.1", features = ["time", "io-util"], optional = true } +tokio = { version = "1.8.1", features = ["io-util"], optional = true } # curl_client [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -94,10 +94,11 @@ async-std = { version = "1.9.0", features = ["unstable", "attributes"] } portpicker = "0.1.1" tide = { version = "0.16.0", default-features = false, features = ["h1-server"] } tide-rustls = "0.3.0" -tokio = { version = "1.8.1", features = ["macros"] } +tokio = { version = "1.8.1", features = ["macros", "time"] } serde = "1.0.126" serde_json = "1.0.64" mockito = "0.30.0" +hyper = { version = "0.14.10", features = ["server"] } [dev-dependencies.getrandom] version = "0.2.3"