pub struct HeaderMap { /* private fields */ }Expand description
A list of (name, value) pairs in insertion order.
Implementations§
Source§impl HeaderMap
impl HeaderMap
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create a map with capacity for n entries (no allocations until exceeded).
Sourcepub fn append(
&mut self,
name: impl Into<HeaderName>,
value: impl Into<HeaderValue>,
)
pub fn append( &mut self, name: impl Into<HeaderName>, value: impl Into<HeaderValue>, )
Append (name, value) to the map. Allows duplicate names — use this
only for headers that are semantically multi-valued (Set-Cookie,
Via, etc.). For the common case of “set this header to this value”,
use Self::insert.
Sourcepub fn insert(
&mut self,
name: impl Into<HeaderName>,
value: impl Into<HeaderValue>,
)
pub fn insert( &mut self, name: impl Into<HeaderName>, value: impl Into<HeaderValue>, )
Set name to value, replacing any existing entries with the same
name. Matches http::HeaderMap::insert / reqwest::HeaderMap::insert
semantics: a single entry with this name will exist after the call.
The new entry is placed at the position of the first existing match (preserving header order when overwriting), otherwise appended.
Sourcepub fn remove<N: AsHeaderName>(&mut self, name: N) -> usize
pub fn remove<N: AsHeaderName>(&mut self, name: N) -> usize
Remove all entries matching name. Returns the count removed.
Sourcepub fn get<N: AsHeaderName>(&self, name: N) -> Option<&HeaderValue>
pub fn get<N: AsHeaderName>(&self, name: N) -> Option<&HeaderValue>
First value matching name, if any.
Sourcepub fn get_all<N: AsHeaderName>(
&self,
name: N,
) -> impl Iterator<Item = &HeaderValue>
pub fn get_all<N: AsHeaderName>( &self, name: N, ) -> impl Iterator<Item = &HeaderValue>
All values matching name, in insertion order.
Sourcepub fn contains_key<N: AsHeaderName>(&self, name: N) -> bool
pub fn contains_key<N: AsHeaderName>(&self, name: N) -> bool
Whether at least one entry matches name.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
pub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
Iterate entries in insertion order.
Sourcepub fn extend(&mut self, other: HeaderMap)
pub fn extend(&mut self, other: HeaderMap)
Append all entries from other in their original order. Duplicates are
preserved (this does not deduplicate against self).
Sourcepub fn merge_replacing(&mut self, other: HeaderMap)
pub fn merge_replacing(&mut self, other: HeaderMap)
Append all entries from other, with later names winning over earlier ones
in self. Within other, all entries are kept (even duplicate names).