Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #94

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ authors = [
]
readme = "README.md"
edition = "2018"
include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"]

[package.metadata.docs.rs]
features = ["docs"]
Expand All @@ -35,42 +36,42 @@ 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 }
deadpool = { version = "0.7.0", optional = true }
futures = { version = "0.3.8", 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.15", 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.*", optional = true, package = "rustls" }

# hyper_client
hyper = { version = "0.13.6", features = ["tcp"], optional = true }
hyper-tls = { version = "0.4.3", optional = true }
futures-util = { version = "0.3.5", features = ["io"], optional = true }
tokio = { version = "0.2", features = ["time"], 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 = ["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]
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",
Expand All @@ -89,15 +90,16 @@ 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"] }
serde = "1.0"
serde_json = "1.0"
mockito = "0.23.3"
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", "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"
version = "0.2.3"
features = ["js"]
27 changes: 7 additions & 20 deletions src/h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<SocketAddr, Pool<TcpStream, std::io::Error>>;
type HttpPool = DashMap<SocketAddr, Pool<TcpConnection>>;
#[cfg(any(feature = "native-tls", feature = "rustls"))]
type HttpsPool = DashMap<SocketAddr, Pool<TlsStream<TcpStream>, Error>>;
type HttpsPool = DashMap<SocketAddr, Pool<TlsConnection>>;

/// 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"))]
Expand Down Expand Up @@ -194,10 +185,8 @@ impl HttpClient for H1Client {
pool_ref
} else {
let manager = TcpConnection::new(addr, self.config.clone());
let pool = Pool::<TcpStream, std::io::Error>::new(
manager,
self.max_concurrent_connections,
);
let pool =
Pool::<TcpConnection>::new(manager, self.max_concurrent_connections);
self.http_pools.insert(addr, pool);
self.http_pools.get(&addr).unwrap()
};
Expand Down Expand Up @@ -231,10 +220,8 @@ impl HttpClient for H1Client {
pool_ref
} else {
let manager = TlsConnection::new(host.clone(), addr, self.config.clone());
let pool = Pool::<TlsStream<TcpStream>, Error>::new(
manager,
self.max_concurrent_connections,
);
let pool =
Pool::<TlsConnection>::new(manager, self.max_concurrent_connections);
self.https_pools.insert(addr, pool);
self.https_pools.get(&addr).unwrap()
};
Expand Down
8 changes: 5 additions & 3 deletions src/h1/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ impl TcpConnection {
}

pub(crate) struct TcpConnWrapper {
conn: Object<TcpStream, std::io::Error>,
conn: Object<TcpConnection>,
}
impl TcpConnWrapper {
pub(crate) fn new(conn: Object<TcpStream, std::io::Error>) -> Self {
pub(crate) fn new(conn: Object<TcpConnection>) -> Self {
Self { conn }
}
}
Expand Down Expand Up @@ -61,7 +61,9 @@ impl AsyncWrite for TcpConnWrapper {
}

#[async_trait]
impl Manager<TcpStream, std::io::Error> for TcpConnection {
impl Manager for TcpConnection {
type Type = TcpStream;
type Error = std::io::Error;
async fn create(&self) -> Result<TcpStream, std::io::Error> {
let tcp_stream = TcpStream::connect(self.addr).await?;

Expand Down
8 changes: 5 additions & 3 deletions src/h1/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ impl TlsConnection {
}

pub(crate) struct TlsConnWrapper {
conn: Object<TlsStream<TcpStream>, Error>,
conn: Object<TlsConnection>,
}
impl TlsConnWrapper {
pub(crate) fn new(conn: Object<TlsStream<TcpStream>, Error>) -> Self {
pub(crate) fn new(conn: Object<TlsConnection>) -> Self {
Self { conn }
}
}
Expand Down Expand Up @@ -70,7 +70,9 @@ impl AsyncWrite for TlsConnWrapper {
}

#[async_trait]
impl Manager<TlsStream<TcpStream>, Error> for TlsConnection {
impl Manager for TlsConnection {
type Type = TlsStream<TcpStream>;
type Error = Error;
async fn create(&self) -> Result<TlsStream<TcpStream>, Error> {
let raw_stream = async_std::net::TcpStream::connect(self.addr).await?;

Expand Down
6 changes: 4 additions & 2 deletions src/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/isahc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down