请求体上限 2MB → 20MB(带图对话 413)

起因:会话 1790234457104-wwgr3uq 报
`413 请求体超过上限 2000000 字节`。dump 显示 agent_state 达 2,688,007 字节:
生成的 PNG 以 base64 内联进对话历史(单张 100KB~750KB),两条 assistant 消息
就占 2.5MB,把网关自有的 2MB 限制顶爆。

- server.max_body_size: 2_000_000 → 20_000_000(config.py 默认值 +
  gateway.yaml + _opt_int 兜底三处同步)。
- nginx 侧无需改动:全局 nginx.conf 已是 client_max_body_size 50m,
  两个站点 conf 未单独设置 → 实际生效值 50m > 20m。
- 保留限制(只调大数字,不放开),内部网关 + nginx 两层仍在把关。
- 新增回归 test_server_max_body_size_is_20mb 钉住三处一致
  (配置默认值 / YAML 现值 / 兜底解析)→ 202 passed / 0 failed。

上线实测(pid 3525434):3MB 与 19MB 请求体均过体积检查到鉴权层(401),
21MB 精确 413 且报「请求体超过上限 20000000 字节」。
This commit is contained in:
api-gateway committed 2026-09-24 16:10:07 +08:00
1 parent 64054ad920
commit 09df80d137
4 files changed
+48 -3

No files matched your search

+2 -2
View File
@@ -312,7 +312,7 @@ class ServerConfig:
hot_reload_interval: int = 15 # 重载检查间隔(秒)
metrics_enabled: bool = True # 是否记录调用指标
rate_limit_rps: float | None = None # 全局单 user QPS 上限(None=不限)
max_body_size: int = 2_000_000 # 请求体字节上限(防 DDoS)
max_body_size: int = 20_000_000 # 请求体字节上限(防 DDoS;2026-09-24 由 2MB 提到 20MB,见 gateway.yaml 注释)
cors_origins: list[str] = field(default_factory=lambda: ["*"])
graceful_shutdown: int = 30 # 优雅关闭等待秒
# ── 防滥用 / 安全 ──
@@ -846,7 +846,7 @@ def parse_config(raw: dict[str, Any]) -> GatewayConfig:
hot_reload_interval=_opt_int(srv_raw.get("hot_reload_interval"), "server.hot_reload_interval", 15, minimum=1),
metrics_enabled=_opt_bool(srv_raw.get("metrics_enabled"), "server.metrics_enabled", True),
rate_limit_rps=_opt_float(srv_raw.get("rate_limit_rps")),
max_body_size=_opt_int(srv_raw.get("max_body_size"), "server.max_body_size", 2_000_000, minimum=1),
max_body_size=_opt_int(srv_raw.get("max_body_size"), "server.max_body_size", 20_000_000, minimum=1),
cors_origins=list(srv_raw.get("cors_origins", ["*"])),
graceful_shutdown=_opt_int(srv_raw.get("graceful_shutdown"), "server.graceful_shutdown", 30, minimum=0),
batch_max_concurrency=_opt_int(srv_raw.get("batch_max_concurrency"), "server.batch_max_concurrency", 16, minimum=1),