fix(backend): API 文本输入加 max_length + 请求体大小中间件(CR-H9)

This commit is contained in:
Yaojia Wang
2026-07-08 10:53:44 +02:00
parent 26f10d023d
commit e1a24a2c2c
13 changed files with 223 additions and 30 deletions

View File

@@ -14,7 +14,11 @@ from ww_db import get_sessionmaker
from ww_shared import AppError, ErrorBody, ErrorCode, ErrorEnvelope
from ww_api.logging_config import configure_logging, get_logger
from ww_api.middleware import REQUEST_ID_HEADER, request_id_middleware
from ww_api.middleware import (
REQUEST_ID_HEADER,
body_size_limit_middleware,
request_id_middleware,
)
from ww_api.routers import (
chain,
foreshadow,
@@ -74,6 +78,8 @@ def create_app() -> FastAPI:
allow_headers=["content-type", "authorization", REQUEST_ID_HEADER],
)
app.middleware("http")(request_id_middleware)
# 请求体大小守卫CR-H9在路由前拦截超大 body直接 413。
app.middleware("http")(body_size_limit_middleware)
@app.exception_handler(AppError)
async def _app_error_handler(request: Request, exc: AppError) -> JSONResponse: