pub struct Headers { /* private fields */ }Expand description
Case-insensitive HTTP header container.
Debug formatting redacts values for header names recognised as
sensitive (see crate::redact::SENSITIVE_HEADERS) so that
logging, error formatting, and panic messages do not leak
credentials. Ordinary iteration (iter, get, get_all,
keys) is intentionally not redacted — diagnostics are the
only output channel that needs to be safe by default.
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn insert(&mut self, name: &str, value: &str) -> Result<()>
pub fn insert(&mut self, name: &str, value: &str) -> Result<()>
Insert a header, replacing any existing value with the same name.
§Errors
Returns an error if the name or value is not valid.
Sourcepub fn append(&mut self, name: &str, value: &str) -> Result<()>
pub fn append(&mut self, name: &str, value: &str) -> Result<()>
Append a header value, allowing multiple values for the same name.
§Errors
Returns an error if the name or value is not valid.
Sourcepub fn get(&self, name: &str) -> Option<&HeaderValue>
pub fn get(&self, name: &str) -> Option<&HeaderValue>
Get a header value by name.
Sourcepub fn get_all(&self, name: &str) -> Vec<&HeaderValue>
pub fn get_all(&self, name: &str) -> Vec<&HeaderValue>
Get all values for a header by name.
Sourcepub fn get_str(&self, name: &str) -> Option<Result<&str, ToStrError>>
pub fn get_str(&self, name: &str) -> Option<Result<&str, ToStrError>>
Get a header value as a string by name.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true if the headers contain a value for the given name.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
pub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
Iterate over all header name-value pairs.
Sourcepub fn keys(&self) -> impl Iterator<Item = &HeaderName>
pub fn keys(&self) -> impl Iterator<Item = &HeaderName>
Iterate over all header names.
Sourcepub fn extend(&mut self, other: &Self)
pub fn extend(&mut self, other: &Self)
Extend these headers by appending all values from another set.
This is append-only: existing values for a name are preserved and
values from other are appended, potentially creating duplicates
(e.g. two Content-Type values). This preserves multi-value headers
like Set-Cookie. Callers that need replacement semantics should
remove the header name first, as the request pipeline does when
applying request headers over client defaults, or use
Self::extend_replacing.
Sourcepub fn extend_replacing(&mut self, other: &Self)
pub fn extend_replacing(&mut self, other: &Self)
Extend by replacing values for names present in other.
For each header name in other, any existing values in self are
removed before appending the values from other. Multi-value headers
from other (e.g. Set-Cookie) are preserved.
Sourcepub fn remove(&mut self, name: &str) -> Option<HeaderValue>
pub fn remove(&mut self, name: &str) -> Option<HeaderValue>
Remove a header by name (case-insensitive).
Sourcepub fn into_inner(self) -> HeaderMap
pub fn into_inner(self) -> HeaderMap
Consume and return the inner HeaderMap.