Skip to content

ResponseContext

[Source]

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.

class ref ResponseContext

Public Functions

status

[Source]

Return the response status.

fun box status()
: Status val

Returns


body

[Source]

Return the response body, or None for streaming responses.

fun box body()
: (String val | Array[U8 val] val | None val)

Returns


is_streaming

[Source]

Return true if this was a streaming response.

fun box is_streaming()
: Bool val

Returns


request

[Source]

Return the original HTTP request.

fun box request()
: Request val

Returns


set_status

[Source]

Replace the response status.

No-op for streaming responses (status already on wire).

fun ref set_status(
  status': Status val)
: None val

Parameters

Returns


set_header

[Source]

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).

fun ref set_header(
  name: String val,
  value: String val)
: None val

Parameters

Returns


add_header

[Source]

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.

fun ref add_header(
  name: String val,
  value: String val)
: None val

Parameters

Returns


set_body

[Source]

Replace the response body.

Content-Length is recalculated automatically at serialization time. No-op for streaming responses (chunks already sent).

fun ref set_body(
  body': (String val | Array[U8 val] val))
: None val

Parameters

Returns