pub struct HeaderMap { /* private fields */ }Expand description
A compact header map using SmallVec for inline storage.
Stores up to 12 headers inline (on the stack), only allocating on the heap if more headers are added.
§Example
use armature_core::headers::HeaderMap;
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json");
headers.insert("Accept", "text/html");
assert_eq!(headers.get("content-type"), Some(&"application/json".to_string()));
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_ignore_case(&self, name: &str) -> Option<&String>
pub fn get_ignore_case(&self, name: &str) -> Option<&String>
Get header value by name, with lowercase fallback.
First tries exact match, then lowercase. This handles the common case where headers might be stored in different cases.
Sourcepub fn insert(
&mut self,
name: impl Into<String>,
value: impl Into<String>,
) -> Option<String>
pub fn insert( &mut self, name: impl Into<String>, value: impl Into<String>, ) -> Option<String>
Insert a header, replacing any existing header with same name.
Returns the old value if replaced.
Sourcepub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)
Append a header (allows duplicates).
Unlike insert, this doesn’t replace existing headers.
Use for headers that can have multiple values (e.g., Set-Cookie).
Sourcepub fn remove(&mut self, name: &str) -> Option<String>
pub fn remove(&mut self, name: &str) -> Option<String>
Remove a header by name (case-insensitive).
Returns the removed value if found.
Sourcepub fn remove_all(&mut self, name: &str) -> usize
pub fn remove_all(&mut self, name: &str) -> usize
Remove all headers with given name (case-insensitive).
Returns number of headers removed.
Sourcepub fn get_all(&self, name: &str) -> Vec<&String>
pub fn get_all(&self, name: &str) -> Vec<&String>
Get all values for a header name (for multi-value headers).
Sourcepub fn to_hash_map(&self) -> HashMap<String, String>
pub fn to_hash_map(&self) -> HashMap<String, String>
Convert to HashMap (for compatibility).
Sourcepub fn from_hash_map(map: HashMap<String, String>) -> Self
pub fn from_hash_map(map: HashMap<String, String>) -> Self
Create from HashMap.
Sourcepub fn content_type(&self) -> Option<&String>
pub fn content_type(&self) -> Option<&String>
Get Content-Type header.
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Get Content-Length header as usize.
Get Authorization header.
Sourcepub fn user_agent(&self) -> Option<&String>
pub fn user_agent(&self) -> Option<&String>
Get User-Agent header.
Get Cookie header.
Sourcepub fn is_keep_alive(&self) -> bool
pub fn is_keep_alive(&self) -> bool
Check if Keep-Alive connection.
Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Check if chunked transfer encoding.
Sourcepub fn set_content_type(&mut self, value: impl Into<String>)
pub fn set_content_type(&mut self, value: impl Into<String>)
Set Content-Type header.
Sourcepub fn set_content_length(&mut self, len: usize)
pub fn set_content_length(&mut self, len: usize)
Set Content-Length header.