pub struct Headers { /* private fields */ }Expand description
HTTP headers collection.
Header names are normalized to lowercase at insertion time for case-insensitive matching. Lookups avoid allocation when the lookup key is already lowercase.
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn get(&self, name: &str) -> Option<&[u8]>
pub fn get(&self, name: &str) -> Option<&[u8]>
Get a header value by name (case-insensitive).
Avoids heap allocation when the lookup key is already lowercase.
Sourcepub fn insert(&mut self, name: impl Into<String>, value: impl Into<Vec<u8>>)
pub fn insert(&mut self, name: impl Into<String>, value: impl Into<Vec<u8>>)
Insert a header.
The header name is normalized to lowercase.
Sourcepub fn insert_from_slice(&mut self, name: &str, value: &[u8])
pub fn insert_from_slice(&mut self, name: &str, value: &[u8])
Insert a header from borrowed slices with minimal allocation.
This is an optimized fast path for parsing that:
- Avoids double allocation for header names
- Lowercases in a single pass when needed
- Only allocates for the value copy
Sourcepub fn insert_lowercase(&mut self, name: String, value: Vec<u8>)
pub fn insert_lowercase(&mut self, name: String, value: Vec<u8>)
Insert a header with an already-lowercase name.
§Safety Note
This method assumes the name is already lowercase. If it contains
uppercase characters, lookups may fail. Use insert or
insert_from_slice for untrusted input.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &[u8])>
pub fn iter(&self) -> impl Iterator<Item = (&str, &[u8])>
Iterate over all headers as (name, value) pairs.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Headers
impl RefUnwindSafe for Headers
impl Send for Headers
impl Sync for Headers
impl Unpin for Headers
impl UnwindSafe for Headers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).