Skip to content

Commit c5822d4

Browse files
committed
refactor: transfert http compression features to the aggregator client crate
Not enabled by default on the crate, but enabled in the signer and the aggregator (to keep existing behavior) + add a test to check that the compression is enabled in signer, aggregator, and aggregator-client (for the later only if the http compression feature is enabled) + signer: simplify dependencies following shared aggregator client usage
1 parent 244740d commit c5822d4

File tree

9 files changed

+62
-22
lines changed

9 files changed

+62
-22
lines changed

Cargo.lock

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

internal/mithril-aggregator-client/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ include = ["**/*.rs", "Cargo.toml", "README.md"]
1313
[lib]
1414
crate-type = ["lib", "cdylib", "staticlib"]
1515

16+
[features]
17+
default = []
18+
19+
# Support compressed traffic with `reqwest`
20+
enable-http-compression = ["reqwest/gzip", "reqwest/zstd", "reqwest/deflate", "reqwest/brotli"]
21+
1622
[dependencies]
1723
anyhow = { workspace = true }
1824
async-trait = { workspace = true }

internal/mithril-aggregator-client/src/client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ mod tests {
205205
}
206206
}
207207

208+
#[cfg(feature = "enable-http-compression")]
209+
crate::test_http_compression_is_enabled!();
210+
208211
#[tokio::test]
209212
async fn test_minimal_get_query() {
210213
let (server, client) = setup_server_and_client();

internal/mithril-aggregator-client/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod client;
77
mod error;
88
mod external_trait_impls;
99
pub mod query;
10-
#[cfg(test)]
1110
mod test;
1211

1312
pub use builder::AggregatorClientBuilder;

internal/mithril-aggregator-client/src/test/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#[cfg(test)]
12
use httpmock::MockServer;
23

4+
#[cfg(test)]
35
use crate::AggregatorHttpClient;
46

57
#[cfg(test)]
@@ -29,3 +31,36 @@ macro_rules! assert_error_matches {
2931
}
3032
#[cfg(test)]
3133
pub(crate) use assert_error_matches;
34+
35+
/// Define a test that checks that http compression is enabled for the client.
36+
///
37+
/// Requires `httpmock` in dev-dependencies
38+
#[macro_export]
39+
macro_rules! test_http_compression_is_enabled {
40+
() => {
41+
#[tokio::test]
42+
async fn test_http_compression_is_enabled_and_send_accept_encoding_header_with_correct_values() {
43+
let server = httpmock::MockServer::start();
44+
server.mock(|when, then| {
45+
when.is_true(|req| {
46+
let headers = req.headers();
47+
let accept_encoding_header = headers
48+
.get("accept-encoding")
49+
.expect("Accept-Encoding header not found");
50+
51+
["gzip", "br", "deflate", "zstd"].iter().all(|&encoding| {
52+
accept_encoding_header.to_str().is_ok_and(|h| h.contains(encoding))
53+
})
54+
});
55+
56+
then.status(200).body("[]");
57+
});
58+
59+
let client = $crate::AggregatorHttpClient::builder(server.base_url()).build().unwrap();
60+
client
61+
.send($crate::query::GetCertificatesListQuery::latest())
62+
.await
63+
.expect("GET request should succeed with Accept-Encoding header");
64+
}
65+
};
66+
}

mithril-aggregator/Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ flate2 = "1.1.4"
2626
gcloud-kms = { version = "1.3.1", features = ["auth"] }
2727
gcloud-storage = { version = "1.1.1", features = ["auth"] }
2828
hex = { workspace = true }
29-
mithril-aggregator-client = { path = "../internal/mithril-aggregator-client" }
29+
mithril-aggregator-client = { path = "../internal/mithril-aggregator-client", features = ["enable-http-compression"] }
3030
mithril-cardano-node-chain = { path = "../internal/cardano-node/mithril-cardano-node-chain" }
3131
mithril-cardano-node-internal-database = { path = "../internal/cardano-node/mithril-cardano-node-internal-database" }
3232
mithril-cli-helper = { path = "../internal/mithril-cli-helper" }
@@ -44,13 +44,7 @@ paste = "1.0.15"
4444
percent-encoding = "2.3.2"
4545
rayon = { workspace = true }
4646
regex = "1.12.2"
47-
reqwest = { workspace = true, features = [
48-
"default",
49-
"gzip",
50-
"zstd",
51-
"deflate",
52-
"brotli"
53-
] }
47+
reqwest = { workspace = true, features = ["default"] }
5448
semver = { workspace = true }
5549
serde = { workspace = true }
5650
serde_json = { workspace = true }

mithril-aggregator/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ use tikv_jemallocator::Jemalloc;
6969
#[cfg(all(not(target_env = "msvc"), feature = "jemallocator"))]
7070
#[global_allocator]
7171
static GLOBAL: Jemalloc = Jemalloc;
72+
73+
#[cfg(test)]
74+
mod tests {
75+
mithril_aggregator_client::test_http_compression_is_enabled!();
76+
}

mithril-signer/Cargo.toml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ homepage = { workspace = true }
99
license = { workspace = true }
1010
repository = { workspace = true }
1111

12+
[package.metadata.cargo-machete]
13+
# reqwest re-enables default features (HTTP/2, TLS) that are disabled in workspace
14+
ignored = ["reqwest"]
15+
1216
[features]
1317
default = ["jemallocator"]
1418

@@ -23,7 +27,7 @@ chrono = { workspace = true }
2327
clap = { workspace = true }
2428
config = { workspace = true }
2529
hex = { workspace = true }
26-
mithril-aggregator-client = { path = "../internal/mithril-aggregator-client" }
30+
mithril-aggregator-client = { path = "../internal/mithril-aggregator-client", features = ["enable-http-compression"] }
2731
mithril-cardano-node-chain = { path = "../internal/cardano-node/mithril-cardano-node-chain" }
2832
mithril-cardano-node-internal-database = { path = "../internal/cardano-node/mithril-cardano-node-internal-database" }
2933
mithril-cli-helper = { path = "../internal/mithril-cli-helper" }
@@ -38,15 +42,7 @@ mithril-signed-entity-lock = { path = "../internal/signed-entity/mithril-signed-
3842
mithril-signed-entity-preloader = { path = "../internal/signed-entity/mithril-signed-entity-preloader" }
3943
mithril-ticker = { path = "../internal/mithril-ticker" }
4044
rand_core = { workspace = true }
41-
reqwest = { workspace = true, features = [
42-
"default",
43-
"stream",
44-
"gzip",
45-
"zstd",
46-
"deflate",
47-
"brotli"
48-
] }
49-
semver = { workspace = true }
45+
reqwest = { workspace = true, features = ["default"] }
5046
serde = { workspace = true }
5147
serde_json = { workspace = true }
5248
slog = { workspace = true, features = [
@@ -64,7 +60,6 @@ tikv-jemallocator = { version = "0.6.0", optional = true }
6460

6561
[dev-dependencies]
6662
criterion = { version = "0.7.0", features = ["html_reports", "async_tokio"] }
67-
http = "1.3.1"
6863
httpmock = "0.8.1"
6964
mockall = { workspace = true }
7065
prometheus-parse = "0.2.5"

mithril-signer/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ static GLOBAL: Jemalloc = Jemalloc;
4343
pub(crate) mod test_tools {
4444
mithril_common::define_test_logger!();
4545
}
46+
47+
#[cfg(test)]
48+
mod tests {
49+
mithril_aggregator_client::test_http_compression_is_enabled!();
50+
}

0 commit comments

Comments
 (0)