From 164777091dfeb27bd498b8cde980919ad94554fa Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Fri, 18 Sep 2020 21:50:04 -0700 Subject: [PATCH] crate: add hyper-client feature Adds support for `http-client/hyper_client`, including global pooling for one-off surf methods. --- Cargo.toml | 5 +++-- src/client.rs | 12 +++++++++--- src/lib.rs | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1118b3e..8facd4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,9 @@ edition = "2018" # when the default feature set is updated, verify that the `--features` flags in # `.github/workflows/ci.yaml` are updated accordingly default = ["curl-client", "middleware-logger", "encoding"] -h1-client = ["http-client/h1_client", "default-client"] curl-client = ["http-client/curl_client", "once_cell", "default-client"] +h1-client = ["http-client/h1_client", "default-client"] +hyper-client = ["http-client/hyper_client", "once_cell", "default-client", "async-std/tokio02"] wasm-client = ["http-client/wasm_client", "default-client"] default-client = [] middleware-logger = [] @@ -34,7 +35,7 @@ log = { version = "0.4.7", features = ["kv_unstable"] } mime_guess = "2.0.3" serde = "1.0.97" serde_json = "1.0.40" -http-client = { version = "6.0.0", default-features = false } +http-client = { version = "6.1.0", default-features = false } http-types = "2.5.0" async-std = { version = "1.6.0", default-features = false, features = ["std"] } async-trait = "0.1.36" diff --git a/src/client.rs b/src/client.rs index 05c8c75..c87923f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -10,12 +10,18 @@ use cfg_if::cfg_if; cfg_if! { if #[cfg(feature = "curl-client")] { use http_client::isahc::IsahcClient as DefaultClient; - use once_cell::sync::Lazy; - static GLOBAL_CLIENT: Lazy> = Lazy::new(|| Arc::new(DefaultClient::new())); } else if #[cfg(feature = "wasm-client")] { use http_client::wasm::WasmClient as DefaultClient; } else if #[cfg(feature = "h1-client")] { use http_client::h1::H1Client as DefaultClient; + } else if #[cfg(feature = "hyper-client")] { + use http_client::hyper::HyperClient as DefaultClient; + } +} +cfg_if! { + if #[cfg(any(feature = "curl-client", feature = "hyper-client"))] { + use once_cell::sync::Lazy; + static GLOBAL_CLIENT: Lazy> = Lazy::new(|| Arc::new(DefaultClient::new())); } } @@ -137,7 +143,7 @@ impl Client { #[cfg(feature = "default-client")] pub(crate) fn new_shared() -> Self { cfg_if! { - if #[cfg(feature = "curl-client")] { + if #[cfg(any(feature = "curl-client", feature = "hyper-client"))] { Self::with_http_client_internal(GLOBAL_CLIENT.clone()) } else { Self::new() diff --git a/src/lib.rs b/src/lib.rs index e237009..74b8e50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,8 +64,9 @@ //! # Features //! The following features are available. The default features are //! `curl-client`, `middleware-logger`, and `encoding` -//! - __`h1-client`:__ use `async-h1` as the HTTP backend. //! - __`curl-client` (default):__ use `curl` (through `isahc`) as the HTTP backend. +//! - __`h1-client`:__ use `async-h1` as the HTTP backend. +//! - __`hyper-client`:__ use `hyper` (hyper.rs) as the HTTP backend. //! - __`wasm-client`:__ use `window.fetch` as the HTTP backend. //! - __`middleware-logger` (default):__ enables logging requests and responses using a middleware. //! - __`encoding` (default):__ enables support for body encodings other than utf-8