StreamingResponse
struct StreamingResponse[B: Body]An HTTP/1.1 response whose body is produced incrementally.
Fields:
status: HTTP status code (use Status.* constants).
reason: Status reason phrase (e.g. "OK").
headers: Response headers (owned HeaderMap).
version: HTTP version string (default "HTTP/1.1").
body: The streaming body source. Must implement the
Body trait. Common impls: InlineBody
(single-chunk, Content-Length framing) and
ChunkedBody[Source] (multi-chunk,
Transfer-Encoding: chunked framing).
Movable but not Copyable — the underlying B body source
typically owns mutable state across chunks (an SSE generator
rewrites its buffer in place; a file-streamer holds a file
handle). Copying would split the state in ways callers don't
want.
Wire framing the reactor uses:
body.content_length()returnsSome(n)->Content-Length: nheader, single inline write of N bytes from the firstnext_chunk(subsequent calls returnNone).body.content_length()returnsNone->Transfer-Encoding: chunkedheader, per-chunk RFC 7230 §4.1 framing (hex length + CRLF + bytes + CRLF + final0\r\n\r\n).
Implements Movable
- Fields
status: Intreason: Stringheaders: HeaderMapversion: Stringbody: Btrailers: HeaderMap: Trailer fields emitted after the chunked body (RFC 7230 §4.1.2). Empty by default; callers populate before / during body emission. Only emitted when the body is chunk-framed (body.content_length()returnsNone); ignored under Content-Length framing where trailers are not legal. The serialiser auto-sets theTrailer:header listing the declared trailer names so peers know what to expect.
__init__
def __init__(out self, status: Int, var body: B, reason: String = "", version: String = "HTTP/1.1") Construct a streaming response.
- Args
status: HTTP status code.body: Streaming body (ownership transferred).reason: Status reason phrase. If empty, the reactor will fill in a default from the status code.version: HTTP version string.
ok
def ok(self) -> Bool Return True if the status code is 2xx.
is_redirect
def is_redirect(self) -> Bool Return True if the status code is a redirect (3xx).
is_client_error
def is_client_error(self) -> Bool Return True if the status code is a client error (4xx).
is_server_error
def is_server_error(self) -> Bool Return True if the status code is a server error (5xx).