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-name) -> list<field-value>;Get all of the values corresponding to a name. If the name is not present
in this fields, an empty list is returned. However, if the name is
present but empty, this is represented by a list with one or more
empty field-values present.
F has
has: func(name: field-name) -> bool;Returns true when the name is present in this fields. If the name is
syntactically invalid, false is returned.
F set
set: func(name: field-name, value: list<field-value>) -> result<_, header-error>;Set all of the values for a name. Clears any existing values for that name, if they have been set.
Fails with header-error.immutable if the fields are immutable.
Fails with header-error.size-exceeded if the name or values would
exceed an implementation-defined size limit.
F delete
delete: func(name: field-name) -> result<_, header-error>;Delete all values for a name. Does nothing if no values for the name exist.
Fails with header-error.immutable if the fields are immutable.
F get-and-delete
get-and-delete: func(name: field-name) -> result<list<field-value>, header-error>;Delete all values for a name. Does nothing if no values for the name exist.
Returns all values previously corresponding to the name, if any.
Fails with header-error.immutable if the fields are immutable.
F append
append: func(name: field-name, value: field-value) -> result<_, header-error>;Append a value for a name. Does not change or delete any existing values for that name.
Fails with header-error.immutable if the fields are immutable.
Fails with header-error.size-exceeded if the value would exceed
an implementation-defined size limit.
F copy-all
copy-all: func() -> list<tuple<field-name, field-value>>;Retrieve the full set of names and values in the Fields. Like the constructor, the list represents each name-value pair.
The outer list represents each name-value pair in the Fields. Names which have multiple values are represented by multiple entries in this list with the same name.
The names and values are always returned in the original casing and in the order in which they will be serialized for transport.
F clone
clone: func() -> fields;Make a deep copy of the Fields. Equivalent in behavior to calling the
fields constructor on the return value of copy-all. The resulting
fields is mutable.
F from-list
from-list: func(entries: list<tuple<field-name, field-value>>) -> result<fields, header-error>;Construct an HTTP Fields.
The resulting fields is mutable.
The list represents each name-value pair in the Fields. Names which have multiple values are represented by multiple entries in this list with the same name.
The tuple is a pair of the field name, represented as a string, and Value, represented as a list of bytes. In a valid Fields, all names 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, if a header was forbidden, or if the entries would exceed an implementation size limit.