ResponseContext¶
Context for response interceptors.
Provides read access to the response status, body, streaming state, and the
original request. Write access to response headers, status, and body is
available via set_status(), set_header(), add_header(), and
set_body().
For streaming responses (is_streaming() is true), all mutations are
silently ignored — headers and status are already on the wire, and body
chunks have already been sent.
Public Functions¶
status¶
Return the response status.
Returns¶
- Status val
body¶
Return the response body, or None for streaming responses.
Returns¶
is_streaming¶
Return true if this was a streaming response.
Returns¶
- Bool val
request¶
Return the original HTTP request.
Returns¶
- Request val
set_status¶
Replace the response status.
No-op for streaming responses (status already on wire).
Parameters¶
- status': Status val
Returns¶
- None val
set_header¶
Set or replace a response header.
Removes any existing entries with the same name (case-insensitive per RFC 7230 section 3.2) and adds a new one with the name lowercased. No-op for streaming responses (headers already on wire).
Parameters¶
Returns¶
- None val
add_header¶
Add a response header without removing existing entries.
The name is lowercased for consistency. Use for multi-value headers like
Set-Cookie. No-op for streaming responses.
Parameters¶
Returns¶
- None val
set_body¶
Replace the response body.
Content-Length is recalculated automatically at serialization time. No-op for streaming responses (chunks already sent).
Parameters¶
Returns¶
- None val