Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(api): decompress gzip-encoded request bodies on both routers

Vincenzo Lombardod79e24a1a737
diff --git a/engine/Cargo.lock b/engine/Cargo.lock
index cd412f7cc..371213966 100644
--- a/engine/Cargo.lock
+++ b/engine/Cargo.lock
@@ -215,6 +215,18 @@ dependencies = [
"syn",
]
+[[package]]
+name = "async-compression"
+version = "0.4.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e79b3f8a79cccc2898f31920fc69f304859b3bd567490f75ebf51ae1c792a9ac"
+dependencies = [
+ "compression-codecs",
+ "compression-core",
+ "pin-project-lite",
+ "tokio",
+]
+
[[package]]
name = "async-stream"
version = "0.3.6"
@@ -811,6 +823,23 @@ dependencies = [
"static_assertions",
]
+[[package]]
+name = "compression-codecs"
+version = "0.4.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce2548391e9c1929c21bf6aa2680af86fe4c1b33e6cea9ac1cfeec0bd11218cf"
+dependencies = [
+ "compression-core",
+ "flate2",
+ "memchr",
+]
+
+[[package]]
+name = "compression-core"
+version = "0.4.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc14f565cf027a105f7a44ccf9e5b424348421a1d8952a8fc9d499d313107789"
+
[[package]]
name = "console"
version = "0.15.11"
@@ -5168,12 +5197,16 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
dependencies = [
+ "async-compression",
"bitflags 2.11.1",
"bytes",
+ "futures-core",
"http",
"http-body",
"http-body-util",
"pin-project-lite",
+ "tokio",
+ "tokio-util",
"tower-layer",
"tower-service",
"tracing",
diff --git a/engine/Cargo.toml b/engine/Cargo.toml
index 6fc16761f..5674abae9 100644
--- a/engine/Cargo.toml
+++ b/engine/Cargo.toml
@@ -32,7 +32,7 @@ tokio = { version = "1", features = ["full"] }
# HTTP
axum = { version = "0.7", features = ["macros"] }
tower = "0.4"
-tower-http = { version = "0.5", features = ["cors", "trace", "limit"] }
+tower-http = { version = "0.5", features = ["cors", "trace", "limit", "decompression-gzip"] }
# Serialization
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] }
diff --git a/engine/crates/xerj-api/src/router.rs b/engine/crates/xerj-api/src/router.rs
index 25fa3c873..f6512399c 100644
--- a/engine/crates/xerj-api/src/router.rs
+++ b/engine/crates/xerj-api/src/router.rs
@@ -19,6 +19,7 @@ use axum::{
use tower_http::{
classify::{ServerErrorsAsFailures, SharedClassifier},
cors::{AllowOrigin, Any, CorsLayer},
+ decompression::RequestDecompressionLayer,
limit::RequestBodyLimitLayer,
trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer},
};
@@ -158,6 +159,13 @@ pub fn build_native_router(state: AppState) -> Router {
// gate — bulk ingests legitimately exceed 2MB.
.layer(DefaultBodyLimit::disable())
.layer(RequestBodyLimitLayer::new(body_limit))
+ // Outermost: transparently decompress gzip-encoded request bodies
+ // (Content-Encoding: gzip) before the size limit above sees them, so
+ // the limit bounds decompressed size, not wire size. Real ES clients
+ // routinely compress writes by default (Beats, Logstash, official
+ // client libraries) — without this every such request 400s/500s
+ // trying to JSON-parse raw gzip bytes.
+ .layer(RequestDecompressionLayer::new().gzip(true))
}
// ─────────────────────────────────────────────────────────────────────────────
@@ -770,6 +778,13 @@ pub fn build_es_compat_router(state: AppState) -> Router {
// gate — bulk ingests legitimately exceed 2MB.
.layer(DefaultBodyLimit::disable())
.layer(RequestBodyLimitLayer::new(body_limit))
+ // Outermost: transparently decompress gzip-encoded request bodies
+ // (Content-Encoding: gzip) before the size limit above sees them, so
+ // the limit bounds decompressed size, not wire size. Real ES clients
+ // routinely compress writes by default (Beats, Logstash, official
+ // client libraries) — without this every such request 400s/500s
+ // trying to JSON-parse raw gzip bytes.
+ .layer(RequestDecompressionLayer::new().gzip(true))
}
// ─────────────────────────────────────────────────────────────────────────────