pub struct Header(/* private fields */);Expand description
Handle for accessing and mutating HTTP headers.
A Header is scoped to either the request or response, depending on how it
is constructed.
Implementations§
Source§impl Header
impl Header
Sourcepub fn names_iter(&self) -> impl Iterator<Item = Bytes> + use<'_>
pub fn names_iter(&self) -> impl Iterator<Item = Bytes> + use<'_>
Returns an iterator over all header names as raw bytes without allocating into a vector.
Header names are returned in the order provided by the host runtime.
This method is zero-allocation and returns an iterator that yields each
header name as Bytes. For heap-allocated results, use names.
Sourcepub fn names(&self) -> Vec<Bytes>
pub fn names(&self) -> Vec<Bytes>
Returns all header names as raw bytes, allocating into a vector.
Header names are returned in the order provided by the host runtime.
This method collects results into a Vec, which allocates heap memory.
Use names_iter for zero-allocation access.
Sourcepub fn values_iter(&self, name: &[u8]) -> impl Iterator<Item = Bytes> + use<'_>
pub fn values_iter(&self, name: &[u8]) -> impl Iterator<Item = Bytes> + use<'_>
Returns an iterator over all values for the given header name without allocating into a vector.
The name is matched by the host according to its header normalization
rules (often case-insensitive). This method is zero-allocation and returns
an iterator that yields each header value as Bytes. For heap-allocated results,
use values.
Sourcepub fn get(&self, name: &[u8]) -> Option<Bytes>
pub fn get(&self, name: &[u8]) -> Option<Bytes>
Return the first value for the given header name, if present.
Sourcepub fn values(&self, name: &[u8]) -> Vec<Bytes>
pub fn values(&self, name: &[u8]) -> Vec<Bytes>
Returns all values for the given header name, allocating into a vector.
The name is matched by the host according to its header normalization
rules (often case-insensitive). This method collects results into a Vec,
which allocates heap memory. Use values_iter for
zero-allocation access.
Sourcepub fn set(&self, name: &[u8], value: &[u8])
pub fn set(&self, name: &[u8], value: &[u8])
Set a header value, replacing any existing values.
Sourcepub fn entries_iter(&self) -> impl Iterator<Item = (Bytes, Vec<Bytes>)> + '_
pub fn entries_iter(&self) -> impl Iterator<Item = (Bytes, Vec<Bytes>)> + '_
Return all headers as an iterator of names to value lists.
This returns an iterator over all header entries. Each entry contains
the header name paired with a vector containing its associated values.
For zero-allocation access, use names_iter and
values_iter.
Sourcepub fn entries(&self) -> HashMap<Bytes, Vec<Bytes>>
pub fn entries(&self) -> HashMap<Bytes, Vec<Bytes>>
Return all headers as a map of names to value lists.
This collects all names and then queries each set of values, allocating
into a HashMap and multiple Vecs for the values. Each header name is
paired with a vector containing its associated values. Use
entries_iter for zero-allocation access.