Skip to content

ResponseBuilder

[Source]

Build a complete HTTP response as a pre-serialized byte array.

The builder uses a typed state machine to ensure responses are constructed in the correct order: status line, then headers, then body. Each phase returns an interface that exposes only the methods valid for that phase.

The caller is responsible for all response formatting, including setting Content-Length or any other required headers. No headers are injected automatically.

let body: String val = "Hello, World!"
let response: Array[U8] val = ResponseBuilder(StatusOK)
  .add_header("Content-Type", "text/plain")
  .add_header("Content-Length", body.size().string())
  .finish_headers()
  .add_chunk(body)
  .build()

// Send via a Responder:
responder.respond(response)

For use in a val factory, wrap the builder in a recover val block:

_cached = recover val
  ResponseBuilder(StatusOK)
    .add_header("Content-Length", "2")
    .finish_headers()
    .add_chunk("OK")
    .build()
end
primitive val ResponseBuilder

Constructors

create

[Source]

new val create()
: ResponseBuilder val^

Returns


Public Functions

apply

[Source]

Create a builder with the given status and version.

fun box apply(
  status: Status val,
  version: ((HTTP10 val | HTTP11 val) & _Version val) = reference)
: ResponseHeadersBuilder ref

Parameters

Returns


eq

[Source]

fun box eq(
  that: ResponseBuilder val)
: Bool val

Parameters

Returns


ne

[Source]

fun box ne(
  that: ResponseBuilder val)
: Bool val

Parameters

Returns