Skip to content

Headers

[Source]

Collection for headers based on a sorted array we use bisect to insert and get values. We compare the strings case-insensitive when sorting, inserting and getting headers.

We want to use the bytes we get to build the headers as is without changing them, in order to avoid allocation.

This isn't using a hashmap because getting the hash in a case-insensitive manner would require to iterate over single bytes, which isn't as fast as it could be. Also the amount of headers in a request is usually small, so the penalty of doing a binary search isn't as bad.

Getting a header is case insensitive, so you don't need to care about header name casing when asking for a header.

Usage

let headers = Headers
header.set("Connection", "Close") // setting a header, possibly overwriting previous values
header.add("Multiple", "1")       // adding a header, concatenating previous and this value with a comma.
header.add("Multiple", "2")

// getting a header is case-insensitive
match header.get("cOnNeCTiOn")
| let value: String => // do something with value
else
  // not found
end

// iterating over headers
for (name, value) in headers.values() do
  env.out.print(name + ": " + value)
end

// remove all headers from this structure
headers.clear()
class ref Headers

Constructors

create

[Source]

new ref create()
: Headers ref^

Returns


from_map

[Source]

new ref from_map(
  headers: HashMap[String val, String val, HashEq[String val] val] ref)
: Headers ref^

Parameters

Returns


from_seq

[Source]

new ref from_seq(
  headers: ReadSeq[(String val , String val)] box)
: Headers ref^

Parameters

Returns


from_iter

[Source]

new ref from_iter(
  headers: Iterator[(String val , String val)] ref,
  size: USize val = 4)
: Headers ref^

Parameters

Returns


Public Functions

set

[Source]

if a header with name already exists, its value will be overriden with this value.

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

Parameters

Returns


delete

[Source]

If a header with name exists, remove it.

Returns true if a header with that name existed, false otherwise.

fun ref delete(
  name: String val)
: ((String val , String val) | None val)

Parameters

Returns


add

[Source]

If a header with this name already exists, value will be appended after a separating comma.

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

Parameters

Returns


get

[Source]

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

Parameters

Returns


clear

[Source]

fun ref clear()
: None val

Returns


values

[Source]

fun box values()
: Iterator[(String val , String val)] ref

Returns


byte_size

[Source]

size of the given headers including header-separator and crlf.

fun box byte_size()
: USize val

Returns