Skip to content

Commit c60919a

Browse files
committed
feat(client): enable HTTP compression using reqwest features
1 parent 7635d4e commit c60919a

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

Cargo.lock

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

mithril-client/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)