Skip to content

Commit 55c5d6a

Browse files
authored
Merge pull request #234 from Fishrock123/hyper-client
crate: add hyper-client feature
2 parents 14ce915 + 1647770 commit 55c5d6a

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ edition = "2018"
2020
# when the default feature set is updated, verify that the `--features` flags in
2121
# `.github/workflows/ci.yaml` are updated accordingly
2222
default = ["curl-client", "middleware-logger", "encoding"]
23-
h1-client = ["http-client/h1_client", "default-client"]
2423
curl-client = ["http-client/curl_client", "once_cell", "default-client"]
24+
h1-client = ["http-client/h1_client", "default-client"]
25+
hyper-client = ["http-client/hyper_client", "once_cell", "default-client", "async-std/tokio02"]
2526
wasm-client = ["http-client/wasm_client", "default-client"]
2627
default-client = []
2728
middleware-logger = []
@@ -34,7 +35,7 @@ log = { version = "0.4.7", features = ["kv_unstable"] }
3435
mime_guess = "2.0.3"
3536
serde = "1.0.97"
3637
serde_json = "1.0.40"
37-
http-client = { version = "6.0.0", default-features = false }
38+
http-client = { version = "6.1.0", default-features = false }
3839
http-types = "2.5.0"
3940
async-std = { version = "1.6.0", default-features = false, features = ["std"] }
4041
async-trait = "0.1.36"

src/client.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ use cfg_if::cfg_if;
1010
cfg_if! {
1111
if #[cfg(feature = "curl-client")] {
1212
use http_client::isahc::IsahcClient as DefaultClient;
13-
use once_cell::sync::Lazy;
14-
static GLOBAL_CLIENT: Lazy<Arc<DefaultClient>> = Lazy::new(|| Arc::new(DefaultClient::new()));
1513
} else if #[cfg(feature = "wasm-client")] {
1614
use http_client::wasm::WasmClient as DefaultClient;
1715
} else if #[cfg(feature = "h1-client")] {
1816
use http_client::h1::H1Client as DefaultClient;
17+
} else if #[cfg(feature = "hyper-client")] {
18+
use http_client::hyper::HyperClient as DefaultClient;
19+
}
20+
}
21+
cfg_if! {
22+
if #[cfg(any(feature = "curl-client", feature = "hyper-client"))] {
23+
use once_cell::sync::Lazy;
24+
static GLOBAL_CLIENT: Lazy<Arc<DefaultClient>> = Lazy::new(|| Arc::new(DefaultClient::new()));
1925
}
2026
}
2127

@@ -137,7 +143,7 @@ impl Client {
137143
#[cfg(feature = "default-client")]
138144
pub(crate) fn new_shared() -> Self {
139145
cfg_if! {
140-
if #[cfg(feature = "curl-client")] {
146+
if #[cfg(any(feature = "curl-client", feature = "hyper-client"))] {
141147
Self::with_http_client_internal(GLOBAL_CLIENT.clone())
142148
} else {
143149
Self::new()

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464
//! # Features
6565
//! The following features are available. The default features are
6666
//! `curl-client`, `middleware-logger`, and `encoding`
67-
//! - __`h1-client`:__ use `async-h1` as the HTTP backend.
6867
//! - __`curl-client` (default):__ use `curl` (through `isahc`) as the HTTP backend.
68+
//! - __`h1-client`:__ use `async-h1` as the HTTP backend.
69+
//! - __`hyper-client`:__ use `hyper` (hyper.rs) as the HTTP backend.
6970
//! - __`wasm-client`:__ use `window.fetch` as the HTTP backend.
7071
//! - __`middleware-logger` (default):__ enables logging requests and responses using a middleware.
7172
//! - __`encoding` (default):__ enables support for body encodings other than utf-8

0 commit comments

Comments
 (0)