INNER CODE UNIT · Python
_RequestBodySizeLimitMiddleware
MakazhanAlpamys/Soup · src/soup_cli/ui/app.py:42
class _RequestBodySizeLimitMiddleware:
"""Reject an oversized POST body before route/model parsing runs.
Checks ``Content-Length`` first, then streams and counts the actual body
bytes so a missing or understated header cannot bypass the cap. Per-route
limits keep the mechanism shared while allowing small JSON requests and
YAML-bearing configuration requests to use different ceilings.
"""
def __init__(self, app, limits: Mapping[str, int] = _BODY_SIZE_LIMITS) -> None:
self._app = app
self._limits = limits
async def _reject(self, scope, receive, send) -> None:
from starlette.responses import JSONResponse
response = JSONResponse(
status_code=413,