ASGI¶
rn_forge.web.asgi
¶
Framework-independent ASGI middleware and type aliases.
The middleware wraps any ASGI application — FastAPI, Starlette, or Django served over ASGI.
ASGIApp = Callable[[Scope, Receive, Send], Awaitable[None]]
¶
An ASGI application or middleware.
Message = MutableMapping[str, Any]
¶
One ASGI event, in either direction.
Receive = Callable[[], Awaitable[Message]]
¶
The ASGI receive callable.
Scope = MutableMapping[str, Any]
¶
The ASGI connection scope.
Send = Callable[[Message], Awaitable[None]]
¶
The ASGI send callable.
BodySizeLimitMiddleware(app, max_bytes)
¶
Reject a request body over max_bytes with RFC 9110 §15.5.14's 413.
Rejects a declared Content-Length over the limit before the downstream
application runs at all. A streamed body with no (or an understated)
Content-Length is checked as it arrives; :class:ContentTooLarge is
raised out of the wrapped receive so the downstream application's read
aborts, and this middleware sends the 413 itself — unless the downstream
application already started its own response, in which case nothing more
can be done and the partial response stands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
ASGIApp
|
The downstream ASGI application. |
required |
max_bytes
|
int
|
The largest body this middleware admits. |
required |
__call__(scope, receive, send)
async
¶
Run the middleware for one connection.