Skip to content

Commit

Permalink
Merge pull request #234 from Fishrock123/hyper-client
Browse files Browse the repository at this point in the history
crate: add hyper-client feature
  • Loading branch information
Fishrock123 authored Oct 22, 2020
2 parents 14ce915 + 1647770 commit 55c5d6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<DefaultClient>> = 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<Arc<DefaultClient>> = Lazy::new(|| Arc::new(DefaultClient::new()));
}
}

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55c5d6a

Please sign in to comment.