fields
This following block defines the fields resource which corresponds to
HTTP standard Fields. Fields are a common representation used for both
Headers and Trailers.
resource fields;F constructor
constructor: func() -> fields;Construct an empty HTTP Fields.
The resulting fields is mutable.
F get
get: func(name: field-key) -> list<field-value>;Get all of the values corresponding to a key. If the key is not present
in this fields, an empty list is returned. However, if the key is
present but empty, this is represented by a list with one or more
empty field-values present.
F has
has: func(name: field-key) -> bool;Returns true when the key is present in this fields. If the key is
syntactically invalid, false is returned.
F set
set: func(name: field-key, value: list<field-value>) -> result<_, header-error>;Set all of the values for a key. Clears any existing values for that key, if they have been set.
Fails with header-error.immutable if the fields are immutable.
F delete
delete: func(name: field-key) -> result<_, header-error>;Delete all values for a key. Does nothing if no values for the key exist.
Fails with header-error.immutable if the fields are immutable.
F append
append: func(name: field-key, value: field-value) -> result<_, header-error>;Append a value for a key. Does not change or delete any existing values for that key.
Fails with header-error.immutable if the fields are immutable.
F entries
entries: func() -> list<tuple<field-key, field-value>>;Retrieve the full set of keys and values in the Fields. Like the constructor, the list represents each key-value pair.
The outer list represents each key-value pair in the Fields. Keys which have multiple values are represented by multiple entries in this list with the same key.
F clone
clone: func() -> fields;Make a deep copy of the Fields. Equivelant in behavior to calling the
fields constructor on the return value of entries. The resulting
fields is mutable.
F from-list
from-list: func(entries: list<tuple<field-key, field-value>>) -> result<fields, header-error>;Construct an HTTP Fields.
The resulting fields is mutable.
The list represents each key-value pair in the Fields. Keys which have multiple values are represented by multiple entries in this list with the same key.
The tuple is a pair of the field key, represented as a string, and Value, represented as a list of bytes. In a valid Fields, all keys and values are valid UTF-8 strings. However, values are not always well-formed, so they are represented as a raw list of bytes.
An error result will be returned if any header or value was syntactically invalid, or if a header was forbidden.