Resource

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 or is syntactically invalid, 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.invalid-syntax if the field-name or any of the field-values are syntactically invalid.

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.

Fails with header-error.invalid-syntax if the field-name is syntactically invalid.

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.invalid-syntax if the field-name or field-value are syntactically invalid.

F entries

entries: 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 entries. 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.

An error result will be returned if any field-name or field-value is syntactically invalid, or if a field is forbidden.