pub struct HeaderBlock { /* private fields */ }Expand description
An ordered, duplicate-preserving collection of HTTP headers.
Headers are stored as an ordered list of name/value pairs. Duplicate field names are preserved. Case-insensitive lookup by field name is provided.
§Canonical representation
This type is normatively a list, not a map. Dictionary conversion
(via Into<HashMap>) is lossy and should only be used as an explicit
convenience.
Implementations§
Source§impl HeaderBlock
impl HeaderBlock
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a header block with a pre-allocated capacity.
Sourcepub fn push(&mut self, name: HeaderName, value: HeaderValue)
pub fn push(&mut self, name: HeaderName, value: HeaderValue)
Push a validated header field.
Sourcepub fn push_str(
&mut self,
name: impl Into<String>,
value: impl Into<String>,
) -> Result<(), HeaderError>
pub fn push_str( &mut self, name: impl Into<String>, value: impl Into<String>, ) -> Result<(), HeaderError>
Push a header field from string slices.
§Errors
Returns HeaderError if the name or value is invalid.
Sourcepub fn get_first(&self, name: &str) -> Option<&HeaderValue>
pub fn get_first(&self, name: &str) -> Option<&HeaderValue>
Returns the first value for the given header name (case-insensitive).
Sourcepub fn get_all(&self, name: &str) -> Vec<&HeaderValue>
pub fn get_all(&self, name: &str) -> Vec<&HeaderValue>
Returns all values for the given header name (case-insensitive), in order.
Sourcepub fn get_unique(
&self,
name: &str,
) -> Result<Option<&HeaderValue>, DuplicateHeaderError>
pub fn get_unique( &self, name: &str, ) -> Result<Option<&HeaderValue>, DuplicateHeaderError>
Returns the unique value for the given header name (case-insensitive).
§Errors
Returns DuplicateHeaderError if the header appears more than once.
Returns Ok(None) if the header is absent.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true if a header with the given name exists
(case-insensitive).
Sourcepub fn iter(&self) -> impl Iterator<Item = &HeaderField>
pub fn iter(&self) -> impl Iterator<Item = &HeaderField>
Returns an iterator over all header fields.
Trait Implementations§
Source§impl Clone for HeaderBlock
impl Clone for HeaderBlock
Source§fn clone(&self) -> HeaderBlock
fn clone(&self) -> HeaderBlock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more