Skip to content

Headers

[Source]

A collection of HTTP headers with case-insensitive name lookup.

Names are lowercased on storage. Use set() to replace all values for a name, or add() to append an additional value (appropriate for multi-value headers like Set-Cookie).

class ref Headers

Constructors

create

[Source]

Create an empty header collection.

new ref create()
: Headers ref^

Returns


Public Functions

set

[Source]

Set a header, removing any existing entries with the same name.

After this call, get(name) returns value and there is exactly one entry for this name.

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

Parameters

Returns


add

[Source]

Add a header entry without removing existing entries with the same name.

This is appropriate for headers that can appear multiple times (e.g., Set-Cookie). Use set() when you want to replace.

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

Parameters

Returns


get

[Source]

Get the value for the given header name (case-insensitive).

A known set of comma-separated list fields โ€” such as Connection, Accept, Cache-Control, and the other standard request list fields โ€” are treated specially: the values of all lines with this name are combined into one value, joined by commas in the order they appeared, per RFC 9110 ยง5.3. For every other field, the first value is returned. A field not in the known set always returns its first value, so combine such a field's repeated lines yourself (via values()) if you need them. Returns None if no header with that name exists.

The combined value is safe to split on commas for simple-token list fields like Connection. Complex list fields whose elements can contain quoted commas (e.g. Accept) need a quoted-string-aware tokenizer to split correctly โ€” combining here does not change that.

fun box get(
  name: String val)
: (String val | None val)

Parameters

Returns


size

[Source]

Return the number of header entries.

fun box size()
: USize val

Returns


values

[Source]

Iterate over all header entries as Header val objects.

fun box values()
: ArrayValues[Header val, this->Array[Header val] ref] ref

Returns