Trait HeaderValues

Source
pub trait HeaderValues {
Show 28 methods // Required methods fn string_value(&self, name: HeaderName) -> Option<&str>; fn string_values(&self, name: HeaderName) -> Vec<&str>; fn byte_string_value(&self, name: HeaderName) -> Option<ByteString>; fn byte_string_values(&self, name: HeaderName) -> Vec<ByteString>; fn set_value<ValueT>(&mut self, name: HeaderName, value: ValueT) where ValueT: Into<HeaderValue>; fn set_into_header_value<ValueT>(&mut self, name: HeaderName, value: ValueT) where ValueT: IntoHeaderValue; fn set_string_value( &mut self, name: HeaderName, value: &str, ) -> Result<(), InvalidHeaderValue>; // Provided methods fn bool_value(&self, name: HeaderName, default: bool) -> bool { ... } fn parse_value<FromStrT>(&self, name: HeaderName) -> Option<FromStrT> where FromStrT: FromStr, FromStrT::Err: Display { ... } fn preferences<FormatT>(&self, name: HeaderName) -> Preferences<FormatT> where FormatT: Clone + Eq + FromStr { ... } fn duration_value(&self, name: HeaderName) -> Option<Duration> { ... } fn date_value(&self, name: HeaderName) -> Option<HttpDate> { ... } fn set_string_values<IteratorT, NameT, ValueT>( &mut self, name_value_pairs: IteratorT, ) -> Result<(), InvalidHeaderValue> where IteratorT: Iterator<Item = (NameT, ValueT)>, NameT: AsRef<str>, ValueT: AsRef<str> { ... } fn set_bool_value(&mut self, name: HeaderName, value: bool) { ... } fn content_length(&self) -> Option<usize> { ... } fn content_type(&self) -> Option<MediaType> { ... } fn accept(&self) -> Preferences<MediaTypeSelector> { ... } fn accept_encoding(&self) -> Preferences<EncodingHeaderValue> { ... } fn accept_language(&self) -> Preferences<Language> { ... } fn if_modified_since(&self) -> Option<HttpDate> { ... } fn if_none_match(&self) -> Option<ETagMatcher> { ... } fn if_unmodified_since(&self) -> Option<HttpDate> { ... } fn if_match(&self) -> Option<ETagMatcher> { ... } fn authorization_basic(&self) -> Option<(String, String)> { ... } fn content_encoding(&self) -> EncodingHeaderValue { ... } fn content_language(&self) -> Option<FastHashSet<Language>> { ... } fn last_modified(&self) -> Option<HttpDate> { ... } fn etag(&self) -> Option<ETag> { ... }
}
Expand description

Access header values.

Required Methods§

Source

fn string_value(&self, name: HeaderName) -> Option<&str>

Parse a header value as an ASCII string.

None could mean that there is no such header or that it is not a valid ASCII string.

Source

fn string_values(&self, name: HeaderName) -> Vec<&str>

Parse all header values as ASCII strings.

Will skip over non-ASCII values.

Source

fn byte_string_value(&self, name: HeaderName) -> Option<ByteString>

Parse a header value as an ASCII string.

None could mean that there is no such header or that it is not a valid ASCII string.

Unfortunately this is not zero-copy because HeaderValue does not give us access to its inner Bytes.

Source

fn byte_string_values(&self, name: HeaderName) -> Vec<ByteString>

Parse all header values as ASCII strings.

Will skip over non-ASCII values.

Unfortunately this is not zero-copy because HeaderValue does not give us access to its inner Bytes.

Source

fn set_value<ValueT>(&mut self, name: HeaderName, value: ValueT)
where ValueT: Into<HeaderValue>,

Set a header value.

Makes sure to remove existing values first.

Source

fn set_into_header_value<ValueT>(&mut self, name: HeaderName, value: ValueT)
where ValueT: IntoHeaderValue,

Set a header value.

Makes sure to remove existing values first.

Source

fn set_string_value( &mut self, name: HeaderName, value: &str, ) -> Result<(), InvalidHeaderValue>

Set a header string value.

Makes sure to remove existing values first.

Will fail if not an ASCII string.

Provided Methods§

Source

fn bool_value(&self, name: HeaderName, default: bool) -> bool

Parse a header value as a boolean (“true” or “false”) or return a default a value.

Source

fn parse_value<FromStrT>(&self, name: HeaderName) -> Option<FromStrT>
where FromStrT: FromStr, FromStrT::Err: Display,

Parse a header from its ASCII string value.

None could mean that there is no such header or that it is malformed.

Source

fn preferences<FormatT>(&self, name: HeaderName) -> Preferences<FormatT>
where FormatT: Clone + Eq + FromStr,

Parse, combine, and sort all header values as Preferences.

Will skip over malformed values.

Source

fn duration_value(&self, name: HeaderName) -> Option<Duration>

Parse a header value as a Duration.

None could mean that there is no such header or that it is malformed.

See duration-str.

Source

fn date_value(&self, name: HeaderName) -> Option<HttpDate>

Parse a header value as an HttpDate.

None could mean that there is no such header or that it is malformed.

Source

fn set_string_values<IteratorT, NameT, ValueT>( &mut self, name_value_pairs: IteratorT, ) -> Result<(), InvalidHeaderValue>
where IteratorT: Iterator<Item = (NameT, ValueT)>, NameT: AsRef<str>, ValueT: AsRef<str>,

Set header string values.

Invalid header names will be skipped.

Makes sure to remove existing values first for each header.

Will fail if a value is not an ASCII string.

Source

fn set_bool_value(&mut self, name: HeaderName, value: bool)

Set a boolean header value (“true” or “false”).

Makes sure to remove existing values first.

Source

fn content_length(&self) -> Option<usize>

Parse the Content-Length header value.

None could mean that there is no such header or that it is malformed.

Source

fn content_type(&self) -> Option<MediaType>

Parse the Content-Type header value.

None could mean that there is no such header or that it is malformed.

Source

fn accept(&self) -> Preferences<MediaTypeSelector>

Parse, combine, and sort all Accept request header values.

Will skip over malformed values.

Source

fn accept_encoding(&self) -> Preferences<EncodingHeaderValue>

Parse, combine, and sort all Accept-Encoding request header values.

Will skip over malformed values.

Source

fn accept_language(&self) -> Preferences<Language>

Parse, combine, and sort all Accept-Language request header values.

Note that we convert all subtags to lowercase for comparison efficiency.

Will skip over malformed values.

Source

fn if_modified_since(&self) -> Option<HttpDate>

Parse the If-Modified-Since request header value.

None could mean that there is no such header or that it is malformed.

Source

fn if_none_match(&self) -> Option<ETagMatcher>

Parse the If-None-Match request header value.

None could mean that there is no such header or that it is malformed.

Source

fn if_unmodified_since(&self) -> Option<HttpDate>

Parse the If-Unmodified-Since request header value.

None could mean that there is no such header or that it is malformed.

Source

fn if_match(&self) -> Option<ETagMatcher>

Parse the If-Match request header value.

None could mean that there is no such header or that it is malformed.

Source

fn authorization_basic(&self) -> Option<(String, String)>

Parse the Authorization request header value for the Basic scheme.

Expects UTF-8 strings.

Returns the username and password.

None could mean that there is no such header or that it is malformed.

Source

fn content_encoding(&self) -> EncodingHeaderValue

Parse the Content-Encoding response header value.

Defaults to Identity if there is no such header or that is malformed.

Source

fn content_language(&self) -> Option<FastHashSet<Language>>

Parse the Content-Language response header value.

Note that we convert all subtags to lowercase for comparison efficiency.

Despite the header name, there can be more than one language listed. We will skip over duplicates.

Source

fn last_modified(&self) -> Option<HttpDate>

Parse the Last-Modified response header value.

None could mean that there is no such header or that it is malformed.

Source

fn etag(&self) -> Option<ETag>

Parse the ETag response header value.

None could mean that there is no such header or that it is malformed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl HeaderValues for HeaderMap

Source§

fn string_value(&self, name: HeaderName) -> Option<&str>

Source§

fn string_values(&self, name: HeaderName) -> Vec<&str>

Source§

fn byte_string_value(&self, name: HeaderName) -> Option<ByteString>

Source§

fn byte_string_values(&self, name: HeaderName) -> Vec<ByteString>

Source§

fn set_value<ValueT>(&mut self, name: HeaderName, value: ValueT)
where ValueT: Into<HeaderValue>,

Source§

fn set_into_header_value<ValueT>(&mut self, name: HeaderName, value: ValueT)
where ValueT: IntoHeaderValue,

Source§

fn set_string_value( &mut self, name: HeaderName, value: &str, ) -> Result<(), InvalidHeaderValue>

Implementors§