pub struct HeaderMap { /* private fields */ }Expand description
A compact header map using SmallVec for inline storage.
§Example
use armature_core::headers::HeaderMap;
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json");
headers.insert("Accept", "text/html");
// Lookup is case-insensitive; the value comes back as a `&str`.
assert_eq!(headers.get("content-type"), Some("application/json"));
assert!(headers.is_inline()); // Still on stackImplementations§
Source§impl HeaderMap
impl HeaderMap
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create with pre-allocated capacity.
If capacity <= INLINE_HEADERS, no heap allocation occurs.
Sourcepub fn get(&self, name: &str) -> Option<&str>
pub fn get(&self, name: &str) -> Option<&str>
The value of name as UTF-8, case-insensitively.
Returns None for a value that is not valid UTF-8; use
HeaderMap::get_bytes for those.
Sourcepub fn get_bytes(&self, name: &str) -> Option<&Bytes>
pub fn get_bytes(&self, name: &str) -> Option<&Bytes>
The raw value of name, case-insensitively.
Sourcepub fn get_id(&self, id: &HeaderId) -> Option<&Bytes>
pub fn get_id(&self, id: &HeaderId) -> Option<&Bytes>
The raw value for an already-interned name.
The hot-path accessor: no interning, and for a well-known name the comparison is on the enum discriminant.
Sourcepub fn get_ignore_case(&self, name: &str) -> Option<&str>
pub fn get_ignore_case(&self, name: &str) -> Option<&str>
The value of name as UTF-8, case-insensitively.
Identical to HeaderMap::get; kept because call sites use both names.
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Check if header exists (case-insensitive).
HashMap-compatible alias for contains.
Sourcepub fn insert(
&mut self,
name: impl AsRef<str>,
value: impl HeaderValueInput,
) -> Option<Bytes>
pub fn insert( &mut self, name: impl AsRef<str>, value: impl HeaderValueInput, ) -> Option<Bytes>
Insert a header, replacing any existing header with the same name.
Returns the old value if one was replaced.
Sourcepub fn append(&mut self, name: impl AsRef<str>, value: impl HeaderValueInput)
pub fn append(&mut self, name: impl AsRef<str>, value: impl HeaderValueInput)
Append a header, allowing duplicates.
Unlike insert, this does not replace. Use it for fields that may repeat,
such as Set-Cookie.
Sourcepub fn remove(&mut self, name: &str) -> Option<Bytes>
pub fn remove(&mut self, name: &str) -> Option<Bytes>
Remove a header by name (case-insensitive), returning its value.
Sourcepub fn remove_all(&mut self, name: &str) -> usize
pub fn remove_all(&mut self, name: &str) -> usize
Remove every header with the given name, returning how many were removed.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Iterate over headers as (name, value), skipping non-UTF-8 values.
Sourcepub fn iter_raw(&self) -> impl Iterator<Item = (&HeaderId, &Bytes)>
pub fn iter_raw(&self) -> impl Iterator<Item = (&HeaderId, &Bytes)>
Iterate over every header, including those with non-UTF-8 values.
Sourcepub fn keys(&self) -> impl Iterator<Item = &str>
pub fn keys(&self) -> impl Iterator<Item = &str>
Iterate over header names.
HashMap-compatible alias for names.
Sourcepub fn values(&self) -> impl Iterator<Item = &str>
pub fn values(&self) -> impl Iterator<Item = &str>
Iterate over header values, skipping non-UTF-8 ones.
Sourcepub fn get_all(&self, name: &str) -> Vec<&str>
pub fn get_all(&self, name: &str) -> Vec<&str>
Every value for a header name, for multi-value fields.
Sourcepub fn to_hash_map(&self) -> HashMap<String, String>
pub fn to_hash_map(&self) -> HashMap<String, String>
Convert to a HashMap, for compatibility.
Names come out lowercased and non-UTF-8 values are dropped. This
allocates a String per name and value — reach for it only when a
HashMap is genuinely required.
Sourcepub fn from_hash_map(map: HashMap<String, String>) -> Self
pub fn from_hash_map(map: HashMap<String, String>) -> Self
Create from a HashMap.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get the Content-Type header.
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Get the Content-Length header as a usize.
Get the Authorization header.
Sourcepub fn user_agent(&self) -> Option<&str>
pub fn user_agent(&self) -> Option<&str>
Get the User-Agent header.
Get the Cookie header.
Sourcepub fn is_keep_alive(&self) -> bool
pub fn is_keep_alive(&self) -> bool
Check for a keep-alive connection.
Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Check for chunked transfer encoding.
Sourcepub fn set_content_type(&mut self, value: impl HeaderValueInput)
pub fn set_content_type(&mut self, value: impl HeaderValueInput)
Set the Content-Type header.
Sourcepub fn set_content_length(&mut self, len: usize)
pub fn set_content_length(&mut self, len: usize)
Set the Content-Length header.
Trait Implementations§
Source§impl Extend<(String, String)> for HeaderMap
impl Extend<(String, String)> for HeaderMap
Source§fn extend<I: IntoIterator<Item = (String, String)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (String, String)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)