CodeVetter · Repo Unpack · Data flow
encode/starlette
ASGI scope and message streams carry input through middleware and routing into connection objects. Parsing and rendering are generally lazy or explicit, with cached request bodies distinct from consumed streams. Uploads, lifespan state, and sessions have different ownership and cleanup boundaries. Outputs pass through send wrappers, which can modify headers, enforce limits, or collect telemetry before reaching the server.
- Router.app records scope['router'] and the selected route, then merges child_scope; Route.matches converts regex captures into typed path_params, while Mount.matches updates root_path and preserves app_root_path.
- Request.stream consumes http.request chunks until more_body is false and raises ClientDisconnect on disconnect; body joins and caches chunks, and json decodes that cached body with json.loads.
- Request._get_form dispatches by Content-Type; FormParser percent-decodes URL-encoded field names and values into FormData, enforcing field count and combined encoded name/value size through parser callbacks.
- Multipart filename parts become UploadFile objects backed by spooled temporary files; callbacks queue bytes, parse awaits writes and rewinds completed files, and UploadFile offloads writes that would roll onto disk.
- Multipart parsing closes all tracked temporary files on BaseException; successful form ownership passes to FormData, whose close method closes uploads, and Request.close delegates to it.
- Router.lifespan merges yielded mappings into lifespan scope state; connection.state wraps the request scope dictionary, and TestClient copies app_state shallowly into HTTP and WebSocket scopes.
- SessionMiddleware verifies timestamped cookie signatures and decodes base64 JSON into scope['session']; response-start handling adds Vary on access, signs modified nonempty sessions, and expires cleared existing sessions.
- Response renders bytes before sending start/body messages, while StreamingResponse emits chunks with more_body; TestClient captures these messages into BytesIO and returns a buffered httpx-compatible Response, discarding HEAD bodies.