Headers¶
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()
Constructors¶
create¶
Returns¶
- Headers ref^
from_map¶
new ref from_map(
headers: HashMap[String val, String val, HashEq[String val] val] ref)
: Headers ref^
Parameters¶
Returns¶
- Headers ref^
from_seq¶
Parameters¶
Returns¶
- Headers ref^
from_iter¶
new ref from_iter(
headers: Iterator[(String val , String val)] ref,
size: USize val = 4)
: Headers ref^
Parameters¶
Returns¶
- Headers ref^
Public Functions¶
set¶
if a header with name already exists, its value will be overriden with this value.
Parameters¶
Returns¶
- None val
delete¶
If a header with name exists, remove it.
Returns true
if a header with that name existed, false
otherwise.
Parameters¶
- name: String val
Returns¶
add¶
If a header with this name already exists, value will be appended after a separating comma.
Parameters¶
Returns¶
- None val
get¶
Parameters¶
- name: String val
Returns¶
clear¶
Returns¶
- None val
values¶
Returns¶
byte_size¶
size of the given headers including header-separator and crlf.
Returns¶
- USize val