From 3a56e6708abb877a62c5984ce0e9e2735d6cee68 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 14 Feb 2021 17:00:23 +0900 Subject: [PATCH 1/2] Fix h1-client and default-client feature This also adds a CI task to check all feature combinations work properly. --- .github/workflows/ci.yaml | 14 +++++++++++++ Cargo.toml | 6 +++--- src/client.rs | 42 ++++++++++++++++++++++++++++++++++----- src/lib.rs | 10 +++++++++- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a081bd37..16d7463c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 42d9f77f..60a1d249 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 ", + "Yoshua Wuyts ", "dignifiedquire ", "Renée Kooi ", "Jeremiah Senkpiel " @@ -21,7 +21,7 @@ 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"] default-client = [] @@ -35,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.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" diff --git a/src/client.rs b/src/client.rs index 5f450a59..02812ccc 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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; @@ -76,7 +76,15 @@ impl fmt::Debug for Client { } } -#[cfg(feature = "default-client")] +#[cfg(all( + feature = "default-client", + 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() @@ -97,14 +105,30 @@ impl Client { /// let res = client.send(req).await?; /// # Ok(()) } /// ``` - #[cfg(feature = "default-client")] + #[cfg(all( + feature = "default-client", + 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(all( + feature = "default-client", + 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") @@ -140,7 +164,15 @@ impl Client { client } - #[cfg(feature = "default-client")] + #[cfg(all( + feature = "default-client", + 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"))] { diff --git a/src/lib.rs b/src/lib.rs index dc3505a2..2638414e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,7 +96,15 @@ pub use request_builder::RequestBuilder; pub use response::{DecodeError, Response}; cfg_if::cfg_if! { - if #[cfg(feature = "default-client")] { + if #[cfg(all( + feature = "default-client", + 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}; From cbd2185fbcdad53d5cfbab6a5b75536102a95dae Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Mon, 1 Mar 2021 10:40:23 -0800 Subject: [PATCH 2/2] Revert default-client changes This was changed in the previous commit when it didn't need to be 3a56e67 --- .github/workflows/ci.yaml | 2 +- src/client.rs | 42 +++++---------------------------------- src/lib.rs | 10 +--------- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 16d7463c..d24a5577 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -100,4 +100,4 @@ jobs: - 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 + run: cargo hack check --feature-powerset --no-dev-deps --skip=default-client,wasm-client diff --git a/src/client.rs b/src/client.rs index 02812ccc..5f450a59 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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(all(feature = "wasm-client", target_arch = "wasm32"))] { + } 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; @@ -76,15 +76,7 @@ impl fmt::Debug for Client { } } -#[cfg(all( - feature = "default-client", - any( - feature = "curl-client", - all(feature = "wasm-client", target_arch = "wasm32"), - feature = "h1-client", - feature = "hyper-client" - ) -))] +#[cfg(feature = "default-client")] impl Default for Client { fn default() -> Self { Self::new() @@ -105,30 +97,14 @@ impl Client { /// let res = client.send(req).await?; /// # Ok(()) } /// ``` - #[cfg(all( - feature = "default-client", - any( - feature = "curl-client", - all(feature = "wasm-client", target_arch = "wasm32"), - feature = "h1-client", - feature = "hyper-client" - ) - ))] + #[cfg(feature = "default-client")] pub fn new() -> Self { Self::with_http_client(DefaultClient::new()) } pub(crate) fn new_shared_or_panic() -> Self { cfg_if! { - if #[cfg(all( - feature = "default-client", - any( - feature = "curl-client", - all(feature = "wasm-client", target_arch = "wasm32"), - feature = "h1-client", - feature = "hyper-client" - ) - ))] { + if #[cfg(feature = "default-client")] { Self::new_shared() } else { panic!("default client not configured") @@ -164,15 +140,7 @@ impl Client { client } - #[cfg(all( - feature = "default-client", - any( - feature = "curl-client", - all(feature = "wasm-client", target_arch = "wasm32"), - feature = "h1-client", - feature = "hyper-client" - ) - ))] + #[cfg(feature = "default-client")] pub(crate) fn new_shared() -> Self { cfg_if! { if #[cfg(any(feature = "curl-client", feature = "hyper-client"))] { diff --git a/src/lib.rs b/src/lib.rs index 2638414e..dc3505a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,15 +96,7 @@ pub use request_builder::RequestBuilder; pub use response::{DecodeError, Response}; cfg_if::cfg_if! { - if #[cfg(all( - feature = "default-client", - any( - feature = "curl-client", - all(feature = "wasm-client", target_arch = "wasm32"), - feature = "h1-client", - feature = "hyper-client" - ) - ))] { + if #[cfg(feature = "default-client")] { mod one_off; pub use one_off::{connect, delete, get, head, options, patch, post, put, trace};