From 3a75efba92081a62cc07623e0ad304a215bdd8d3 Mon Sep 17 00:00:00 2001 From: argszero Date: Sun, 23 Aug 2026 12:37:06 +0800 Subject: [PATCH] feat(proxy): raise request body limit to 70MB for long LLM contexts (rant 2026-08-22T23:20:00) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit axum default body limit is 2MB — insufficient for long LLM contexts and base64 images. Add tower-http 'limit' feature and wrap the router with RequestBodyLimitLayer(70MB). Real limit still governed by the upstream model context window. 142/142 tests + fmt + clippy green locally. --- Cargo.toml | 2 +- src/main.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cc9f3e5..1116650 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ rust-version = "1.86" axum = { version = "0.7", features = ["macros"] } tokio = { version = "1", features = ["macros", "rt-multi-thread", "time", "signal"] } tower = { version = "0.5", features = ["util"] } -tower-http = { version = "0.5", features = ["cors", "fs", "trace"] } +tower-http = { version = "0.5", features = ["cors", "fs", "trace", "limit"] } hyper = { version = "1.0", features = ["full"] } # HTTP 客户端(上游转发) diff --git a/src/main.rs b/src/main.rs index 64727fe..6ecb806 100644 --- a/src/main.rs +++ b/src/main.rs @@ -210,6 +210,11 @@ async fn main() -> anyhow::Result<()> { let state = routes::AppState::new(conn, cfg, crypto); let app = routes::router() .with_state(state) + // 请求体上限:axum 默认 2MB,对超长 LLM 上下文/图片 base64 不够,放宽到 70MB + //(rant 2026-08-22T23:20:00;真实限制仍由上游模型 context 窗口裁决) + .layer(tower_http::limit::RequestBodyLimitLayer::new( + 70 * 1024 * 1024, + )) .layer(tower_http::trace::TraceLayer::new_for_http()); let listener = tokio::net::TcpListener::bind(&addr).await?;