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

Fix h1-client and default-client feature #282

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,17 @@ jobs:

- name: docs
run: cargo doc --no-deps

check_features:
name: Check feature combinations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Install cargo-hack
run: cargo install cargo-hack

- name: Check all feature combinations works properly
# * `--feature-powerset` - run for the feature powerset of the package
# * `--no-dev-deps` - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
run: cargo hack check --feature-powerset --no-dev-deps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this check takes a long time, it can limit the max number of simultaneous feature flags by passing the --depth flag. (like futures-rs, hyper, etc. do) AFAIK --depth 2 should be sufficient in most cases as described in taiki-e/cargo-hack#58.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "Surf the web - HTTP client framework"
keywords = ["http", "client", "framework", "request", "async"]
categories = ["web-programming", "web-programming::http-client"]
authors = [
"Yoshua Wuyts <yoshuawuyts@gmail.com>",
"Yoshua Wuyts <yoshuawuyts@gmail.com>",
"dignifiedquire <me@dignifiedquire.com>",
"Renée Kooi <renee@kooi.me>",
"Jeremiah Senkpiel <fishrock123@rocketmail.com>"
Expand All @@ -21,9 +21,10 @@ edition = "2018"
# `.github/workflows/ci.yaml` are updated accordingly
default = ["curl-client", "middleware-logger", "encoding"]
curl-client = ["http-client/curl_client", "once_cell", "default-client"]
h1-client = ["http-client/h1_client", "default-client"]
h1-client = ["http-client/h1_client", "http-client/native-tls", "default-client"]
hyper-client = ["http-client/hyper_client", "once_cell", "default-client", "async-std/tokio02"]
wasm-client = ["http-client/wasm_client", "default-client"]
# this feature flag is no longer necessary.
default-client = []
Comment on lines +27 to 28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All clients enable this feature and all cfg(feature = "default-client") removed, so this feature is no longer used.

middleware-logger = []
# requires web-sys for TextDecoder on wasm
Expand All @@ -35,7 +36,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.1.0", default-features = false }
http-client = { version = "6.3.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
30 changes: 25 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cfg_if::cfg_if;
cfg_if! {
if #[cfg(feature = "curl-client")] {
use http_client::isahc::IsahcClient as DefaultClient;
} else if #[cfg(feature = "wasm-client")] {
} else if #[cfg(all(feature = "wasm-client", target_arch = "wasm32"))] {
use http_client::wasm::WasmClient as DefaultClient;
} else if #[cfg(feature = "h1-client")] {
use http_client::h1::H1Client as DefaultClient;
Expand Down Expand Up @@ -76,7 +76,12 @@ impl fmt::Debug for Client {
}
}

#[cfg(feature = "default-client")]
#[cfg(any(
feature = "curl-client",
all(feature = "wasm-client", target_arch = "wasm32"),
feature = "h1-client",
feature = "hyper-client"
))]
impl Default for Client {
fn default() -> Self {
Self::new()
Expand All @@ -97,14 +102,24 @@ impl Client {
/// let res = client.send(req).await?;
/// # Ok(()) }
/// ```
#[cfg(feature = "default-client")]
#[cfg(any(
feature = "curl-client",
all(feature = "wasm-client", target_arch = "wasm32"),
feature = "h1-client",
feature = "hyper-client"
))]
pub fn new() -> Self {
Self::with_http_client(DefaultClient::new())
}

pub(crate) fn new_shared_or_panic() -> Self {
cfg_if! {
if #[cfg(feature = "default-client")] {
if #[cfg(any(
feature = "curl-client",
all(feature = "wasm-client", target_arch = "wasm32"),
feature = "h1-client",
feature = "hyper-client"
))] {
Self::new_shared()
} else {
panic!("default client not configured")
Expand Down Expand Up @@ -140,7 +155,12 @@ impl Client {
client
}

#[cfg(feature = "default-client")]
#[cfg(any(
feature = "curl-client",
all(feature = "wasm-client", target_arch = "wasm32"),
feature = "h1-client",
feature = "hyper-client"
))]
pub(crate) fn new_shared() -> Self {
cfg_if! {
if #[cfg(any(feature = "curl-client", feature = "hyper-client"))] {
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ pub use request_builder::RequestBuilder;
pub use response::{DecodeError, Response};

cfg_if::cfg_if! {
if #[cfg(feature = "default-client")] {
if #[cfg(any(
feature = "curl-client",
all(feature = "wasm-client", target_arch = "wasm32"),
feature = "h1-client",
feature = "hyper-client"
))] {
mod one_off;
pub use one_off::{connect, delete, get, head, options, patch, post, put, trace};

Expand Down