From cb1a3eeec5e2390eb829a3c6936bd60d558a6e72 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Sat, 11 Oct 2025 19:45:56 +0000 Subject: [PATCH] chore: Enable compression request features Add features and enable compression for communication with the OPA. --- Cargo.lock | 2 ++ Cargo.toml | 2 +- src/policy.rs | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 538587c1..02e376d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3637,6 +3637,7 @@ version = "0.12.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb" dependencies = [ + "async-compression", "base64 0.22.1", "bytes", "encoding_rs", @@ -3667,6 +3668,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls", + "tokio-util", "tower", "tower-http", "tower-service", diff --git a/Cargo.toml b/Cargo.toml index 52ce23cd..3523650d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ mockall_double = { version = "0.3" } opa-wasm = { version = "^0.1", optional = true } openidconnect = { version = "4.0" } regex = { version = "1.11"} -reqwest = { version = "0.12", features = ["json"] } +reqwest = { version = "0.12", features = ["json", "http2", "gzip", "deflate"] } rmp = { version = "0.8" } schemars = { version = "1.0" } sea-orm = { version = "1.1", features = ["sqlx-mysql", "sqlx-postgres", "runtime-tokio", "runtime-tokio-native-tls"] } diff --git a/src/policy.rs b/src/policy.rs index 081d931d..3d3a169f 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -103,7 +103,11 @@ impl PolicyFactory { #[allow(clippy::needless_update)] #[tracing::instrument(name = "policy.http", err)] pub async fn http(url: Url) -> Result { - let client = Client::new(); + let client = Client::builder() + .tcp_keepalive(std::time::Duration::from_secs(60)) + .gzip(true) + .deflate(true) + .build()?; Ok(Self { http_client: Some(Arc::new(client)), base_url: Some(url.join("/v1/data/")?),