From ffabf067152b4e49150c6cc8a9a35c5b75beddbf Mon Sep 17 00:00:00 2001 From: jmwample Date: Fri, 16 May 2025 10:12:38 -0600 Subject: [PATCH] Cherry-pick from https://github.com/nymtech/nym/commit/f6846bf94a190baf07eec4edac9ddb3a34451d30 --- common/http-api-client/Cargo.toml | 13 +++++++++++-- common/http-api-client/src/lib.rs | 23 +++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/common/http-api-client/Cargo.toml b/common/http-api-client/Cargo.toml index 79a291e827..4753efc90d 100644 --- a/common/http-api-client/Cargo.toml +++ b/common/http-api-client/Cargo.toml @@ -12,7 +12,13 @@ license.workspace = true [dependencies] async-trait = { workspace = true } -reqwest = { workspace = true, features = ["json", "gzip"] } +reqwest = { workspace = true, features = [ + "json", + "gzip", + "deflate", + "brotli", + "zstd", +] } http.workspace = true url = { workspace = true } once_cell = { workspace = true } @@ -30,7 +36,10 @@ mime = { workspace = true } nym-bin-common = { path = "../bin-common" } [target."cfg(not(target_arch = \"wasm32\"))".dependencies] -hickory-resolver = { workspace = true, features = ["dns-over-https-rustls", "webpki-roots"] } +hickory-resolver = { workspace = true, features = [ + "dns-over-https-rustls", + "webpki-roots", +] } # for request timeout until https://github.com/seanmonstar/reqwest/issues/1135 is fixed [target."cfg(target_arch = \"wasm32\")".dependencies.wasmtimer] diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 5a360f7be1..ec44fcc7d7 100644 --- a/common/http-api-client/src/lib.rs +++ b/common/http-api-client/src/lib.rs @@ -265,14 +265,18 @@ impl ClientBuilder { #[cfg(not(target_arch = "wasm32"))] let reqwest_client_builder = { - let r = reqwest::ClientBuilder::new(); - - // Note this is extra as the `gzip` feature for `reqwest` crate should be enabled which - // `"Enable[s] auto gzip decompression by checking the Content-Encoding response header."` + // Note: I believe the manual enable calls for the compression methods are extra + // as the various compression features for `reqwest` crate should be enabled + // just by including the feature which: + // `"Enable[s] auto decompression by checking the Content-Encoding response header."` // - // I am going to leave it here anyways so that gzip decompression is attempted even if - // that feature is removed. - r.gzip(true) + // I am going to leave these here anyways so that removing a decompression method + // from the features list will throw an error if it is not also removed here. + reqwest::ClientBuilder::new() + .gzip(true) + .deflate(true) + .brotli(true) + .zstd(true) }; ClientBuilder { @@ -535,11 +539,6 @@ impl ApiClientCore for Client { let mut request = self.reqwest_client.request(method.clone(), url); - // Indicate that compressed responses are preferred, but if not supported other encodings are fine. - // TODO: Down the road we can be more selective about adding this, but it's inclusion here guarantees - // that we use compression when available. - request = request.header(reqwest::header::ACCEPT_ENCODING, "gzip;q=1.0, *;q=0.5"); - if let Some(body) = json_body { request = request.json(body); }