From 58aa8c0c224e44cfee0873f1deaa81171b0250a1 Mon Sep 17 00:00:00 2001 From: BennyFranciscus <268274351+BennyFranciscus@users.noreply.github.com> Date: Thu, 26 Mar 2026 04:38:56 +0000 Subject: [PATCH] fix(actix): use gzip level 1 instead of default level 6 The Compress middleware uses gzip level 6 by default, but the benchmark spec requires level 1. Manually compress with flate2 Compression::fast() (level 1) in the compression handler and set Content-Encoding: gzip so the middleware skips re-compressing. --- frameworks/actix/Cargo.toml | 1 + frameworks/actix/src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frameworks/actix/Cargo.toml b/frameworks/actix/Cargo.toml index edfa35da..53242f67 100644 --- a/frameworks/actix/Cargo.toml +++ b/frameworks/actix/Cargo.toml @@ -12,6 +12,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" num_cpus = "1" rusqlite = { version = "0.31", features = ["bundled"] } +flate2 = "1" [profile.release] opt-level = 3 diff --git a/frameworks/actix/src/main.rs b/frameworks/actix/src/main.rs index 4312b1d2..87c353aa 100644 --- a/frameworks/actix/src/main.rs +++ b/frameworks/actix/src/main.rs @@ -220,10 +220,19 @@ async fn json_endpoint(state: web::Data>) -> HttpResponse { } async fn compression(state: web::Data>) -> HttpResponse { + use flate2::write::GzEncoder; + use flate2::Compression; + use std::io::Write; + + let mut encoder = GzEncoder::new(Vec::new(), Compression::fast()); + encoder.write_all(&state.json_large_cache).unwrap(); + let compressed = encoder.finish().unwrap(); + HttpResponse::Ok() .insert_header(("Content-Type", "application/json")) + .insert_header(("Content-Encoding", "gzip")) .insert_header(("Server", "actix")) - .body(state.json_large_cache.clone()) + .body(compressed) } async fn db_endpoint(req: HttpRequest, db: web::Data) -> HttpResponse {