pub struct Fields { /* private fields */ }Expand description
This following block defines the fields resource which corresponds to
HTTP standard Fields. Fields are a common representation used for both
Headers and Trailers.
A fields may be mutable or immutable. A fields created using the
constructor, from-list, or clone will be mutable, but a fields
resource given by other means (including, but not limited to,
request.headers) might be be immutable. In an immutable fields, the
set, append, and delete operations will fail with
header-error.immutable.
A fields resource should store field-names and field-values in their
original casing used to construct or mutate the fields resource. The fields
resource should use that original casing when returning them from a method.
The fields resource may use a different casing when serializing the value
for transmission, as doing so may improve encoding efficiency.
Implementations may impose limits on individual field values and on total
aggregate field section size. Operations that would exceed these limits
fail with header-error.size-exceeded
Implementations§
Source§impl Fields
impl Fields
Sourcepub fn from_list(
entries: &[(FieldName, FieldValue)],
) -> Result<Fields, HeaderError>
pub fn from_list( entries: &[(FieldName, FieldValue)], ) -> Result<Fields, HeaderError>
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.
Source§impl Fields
impl Fields
Sourcepub fn set(&self, name: &str, value: &[FieldValue]) -> Result<(), HeaderError>
pub fn set(&self, name: &str, value: &[FieldValue]) -> Result<(), HeaderError>
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.
Source§impl Fields
impl Fields
Sourcepub fn get_and_delete(&self, name: &str) -> Result<Vec<FieldValue>, HeaderError>
pub fn get_and_delete(&self, name: &str) -> Result<Vec<FieldValue>, HeaderError>
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.
Source§impl Fields
impl Fields
Sourcepub fn append(&self, name: &str, value: &[u8]) -> Result<(), HeaderError>
pub fn append(&self, name: &str, value: &[u8]) -> Result<(), HeaderError>
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.
Source§impl Fields
impl Fields
Sourcepub fn copy_all(&self) -> Vec<(FieldName, FieldValue)>
pub fn copy_all(&self) -> Vec<(FieldName, FieldValue)>
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.