Skip to content

Commit 52f97d4

Browse files
authored
Merge pull request #2282 from input-output-hk/dlachaume/add-accept-encoding-header-in-signer-and-client-requests
Feat: support compression in HTTP clients
2 parents 7635d4e + d3228da commit 52f97d4

File tree

15 files changed

+256
-20
lines changed

15 files changed

+256
-20
lines changed

Cargo.lock

Lines changed: 59 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-wasm-nodejs/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-wasm-web/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -34,7 +34,13 @@ paste = "1.0.15"
3434
prometheus = "0.13.4"
3535
rayon = "1.10.0"
3636
regex = "1.11.1"
37-
reqwest = { version = "0.12.12", features = ["json"] }
37+
reqwest = { version = "0.12.12", features = [
38+
"json",
39+
"gzip",
40+
"zstd",
41+
"deflate",
42+
"brotli"
43+
] }
3844
semver = "1.0.25"
3945
serde = { version = "1.0.217", features = ["derive"] }
4046
serde_json = "1.0.138"

mithril-client-wasm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client-wasm"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
description = "Mithril client WASM"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -17,7 +17,7 @@ anyhow = "1.0.95"
1717
async-trait = "0.1.86"
1818
chrono = { version = "0.4.39", features = ["serde"] }
1919
futures = "0.3.31"
20-
mithril-client = { path = "../mithril-client", features = ["unstable"] }
20+
mithril-client = { path = "../mithril-client", default-features = false, features = ["unstable", "num-integer-backend"] }
2121
serde = { version = "1.0.217", features = ["derive"] }
2222
serde-wasm-bindgen = "0.6.5"
2323
serde_json = "1.0.138"

mithril-client-wasm/ci-test/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-client-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mithril-dev/mithril-client-wasm",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "Mithril client WASM",
55
"license": "Apache-2.0",
66
"collaborators": [

mithril-client/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client"
3-
version = "0.11.0"
3+
version = "0.11.1"
44
description = "Mithril client library"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -84,7 +84,7 @@ warp = "0.3.7"
8484

8585
[features]
8686
# Include native-tls in reqwest by default
87-
default = ["native-tls", "rug-backend"]
87+
default = ["native-tls", "rug-backend", "enable-http-compression"]
8888

8989
# Full feature set
9090
full = ["fs"]
@@ -105,6 +105,9 @@ rustls-tls-manual-roots = ["reqwest/rustls-tls-manual-roots"]
105105
rustls-tls-webpki-roots = ["reqwest/rustls-tls-webpki-roots"]
106106
rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"]
107107

108+
# Support compressed traffic with `request`
109+
enable-http-compression = ["reqwest/gzip", "reqwest/zstd", "reqwest/deflate", "reqwest/brotli"]
110+
108111
# Enables `rug-backend` features for `mithril-common` dependency
109112
rug-backend = ["mithril-common/rug-backend"]
110113
# Enables `num-integer-backend` features for `mithril-common` dependency

mithril-client/src/aggregator_client.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,4 +850,58 @@ mod tests {
850850
.await
851851
.expect("GET request should succeed");
852852
}
853+
854+
#[tokio::test]
855+
async fn test_client_sends_accept_encoding_header_with_correct_values() {
856+
let (aggregator, client) = setup_server_and_client();
857+
aggregator.mock(|when, then| {
858+
when.matches(|req| {
859+
let headers = req.headers.clone().expect("HTTP headers not found");
860+
let accept_encoding_header = headers
861+
.iter()
862+
.find(|(name, _values)| name.to_lowercase() == "accept-encoding")
863+
.expect("Accept-Encoding header not found");
864+
865+
let header_value = accept_encoding_header.clone().1;
866+
["gzip", "br", "deflate", "zstd"]
867+
.iter()
868+
.all(|&value| header_value.contains(value))
869+
});
870+
871+
then.status(200).body("ok");
872+
});
873+
874+
client
875+
.get_content(AggregatorRequest::ListCertificates)
876+
.await
877+
.expect("GET request should succeed with Accept-Encoding header");
878+
}
879+
880+
#[tokio::test]
881+
async fn test_client_with_custom_headers_sends_accept_encoding_header_with_correct_values() {
882+
let mut http_headers = HashMap::new();
883+
http_headers.insert("Custom-Header".to_string(), "CustomValue".to_string());
884+
let (aggregator, client) = setup_server_and_client_with_custom_headers(http_headers);
885+
aggregator.mock(|when, then| {
886+
when.matches(|req| {
887+
let headers = req.headers.clone().expect("HTTP headers not found");
888+
let accept_encoding_header = headers
889+
.iter()
890+
.find(|(name, _values)| name.to_lowercase() == "accept-encoding")
891+
.expect("Accept-Encoding header not found");
892+
893+
let header_value = accept_encoding_header.clone().1;
894+
["gzip", "br", "deflate", "zstd"]
895+
.iter()
896+
.all(|&value| header_value.contains(value))
897+
});
898+
899+
then.status(200).body("ok");
900+
});
901+
902+
client
903+
.get_content(AggregatorRequest::ListCertificates)
904+
.await
905+
.expect("GET request should succeed with Accept-Encoding header");
906+
}
853907
}

mithril-explorer/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)