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,
incoming-request.headers, outgoing-request.headers) might be be
immutable. In an immutable fields, the set, append, and delete
operations will fail with header-error.immutable.
Implementations§
Source§impl Fields
impl Fields
Sourcepub fn from_list(entries: &[(String, Vec<u8>)]) -> Result<Fields, HeaderError>
pub fn from_list(entries: &[(String, Vec<u8>)]) -> 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.
An error result will be returned if any field-name or field-value is
syntactically invalid, or if a field is forbidden.
Source§impl Fields
impl Fields
Sourcepub fn get(&self, name: &String) -> Vec<Vec<u8>>
pub fn get(&self, name: &String) -> Vec<Vec<u8>>
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.
Source§impl Fields
impl Fields
Sourcepub fn set(&self, name: &String, value: &[Vec<u8>]) -> Result<(), HeaderError>
pub fn set(&self, name: &String, value: &[Vec<u8>]) -> 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.invalid-syntax if the field-name or any of
the field-values are syntactically invalid.
Source§impl Fields
impl Fields
Sourcepub fn append(&self, name: &String, value: &Vec<u8>) -> Result<(), HeaderError>
pub fn append(&self, name: &String, value: &Vec<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.invalid-syntax if the field-name or
field-value are syntactically invalid.
Source§impl Fields
impl Fields
Sourcepub fn entries(&self) -> Vec<(String, Vec<u8>)>
pub fn entries(&self) -> Vec<(String, Vec<u8>)>
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.