pub struct Headers(/* private fields */);http only.Expand description
A collection of headers.
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn get<H: FromHeaders>(&self) -> Result<H>
pub fn get<H: FromHeaders>(&self) -> Result<H>
Gets the headers represented by H, or return an error if the header is not found.
Sourcepub fn get_optional<H: FromHeaders>(&self) -> Result<Option<H>, H::Error>
pub fn get_optional<H: FromHeaders>(&self) -> Result<Option<H>, H::Error>
Gets the headers represented by H, if they are present.
This method returns one of the following three values:
Ok(Some(...))if the relevant headers are present and could be parsed into the value.Ok(None)if the relevant headers are not present, so no attempt to parse them can be made.Err(...)if an error occurred when trying to parse the headers. This likely indicates that the headers are present but invalid.
Sourcepub fn get_optional_string(&self, key: &HeaderName) -> Option<String>
pub fn get_optional_string(&self, key: &HeaderName) -> Option<String>
Optionally get a header value as a String.
Sourcepub fn get_str(&self, key: &HeaderName) -> Result<&str>
pub fn get_str(&self, key: &HeaderName) -> Result<&str>
Get a header value as a str, or err if it is not found.
Sourcepub fn get_optional_str(&self, key: &HeaderName) -> Option<&str>
pub fn get_optional_str(&self, key: &HeaderName) -> Option<&str>
Optionally get a header value as a str.
Sourcepub fn get_as<V, E>(&self, key: &HeaderName) -> Result<V>
pub fn get_as<V, E>(&self, key: &HeaderName) -> Result<V>
Get a header value parsing it as the type, or err if it’s not found or it fails to parse.
Sourcepub fn get_optional_as<V, E>(&self, key: &HeaderName) -> Result<Option<V>>
pub fn get_optional_as<V, E>(&self, key: &HeaderName) -> Result<Option<V>>
Optionally get a header value parsing it as the type, or err if it fails to parse.
Sourcepub fn get_with<'a, V, F, E>(&'a self, key: &HeaderName, parser: F) -> Result<V>
pub fn get_with<'a, V, F, E>(&'a self, key: &HeaderName, parser: F) -> Result<V>
Get a header value using the parser, or err if it is not found or fails to parse.
Sourcepub fn get_optional_with<'a, V, F, E>(
&'a self,
key: &HeaderName,
parser: F,
) -> Result<Option<V>>
pub fn get_optional_with<'a, V, F, E>( &'a self, key: &HeaderName, parser: F, ) -> Result<Option<V>>
Optionally get a header value using the parser, or err if it fails to parse.
Sourcepub fn add<H>(&mut self, header: H) -> Result<(), H::Error>where
H: AsHeaders,
pub fn add<H>(&mut self, header: H) -> Result<(), H::Error>where
H: AsHeaders,
Add headers to the headers collection.
§Errors
The error this returns depends on the type H.
Many header types are infallible, return a Result with Infallible as the error type.
In this case, you can safely .unwrap() the value without risking a panic.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
pub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
Iterate over all the header name/value pairs.
Sourcepub fn remove<K>(&mut self, key: K) -> Option<HeaderValue>where
K: Into<HeaderName>,
pub fn remove<K>(&mut self, key: K) -> Option<HeaderValue>where
K: Into<HeaderName>,
Remove a header by name, returning the previous value if present.