pub struct Accept(pub NonEmptySmallVec<7, QualityValue<Mime>>);Expand description
Accept header, defined in RFC7231
The Accept header field can be used by user agents to specify
response media types that are acceptable. Accept header fields can
be used to indicate that the request is specifically limited to a
small set of desired types, as in the case of a request for an
in-line image
§ABNF
Accept = #( media-range [ accept-params ] )
media-range = ( "*/*"
/ ( type "/" "*" )
/ ( type "/" subtype )
) *( OWS ";" OWS parameter )
accept-params = weight *( accept-ext )
accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ]§Example values
audio/*; q=0.2, audio/basictext/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c
§Examples
use std::iter::FromIterator;
use rama_http_headers::{Accept, specifier::QualityValue, HeaderMapExt};
use rama_http_types::mime;
let mut headers = rama_http_types::HeaderMap::new();
headers.typed_insert(
Accept::new(
QualityValue::new(mime::TEXT_HTML, Default::default()),
)
);use std::iter::FromIterator;
use rama_http_headers::{Accept, specifier::QualityValue, HeaderMapExt};
use rama_http_types::mime;
let mut headers = rama_http_types::HeaderMap::new();
headers.typed_insert(
Accept::new(
QualityValue::new(mime::APPLICATION_JSON, Default::default()),
)
);use std::iter::FromIterator;
use rama_utils::collections::non_empty_smallvec;
use rama_http_headers::{Accept, specifier::QualityValue, HeaderMapExt};
use rama_http_types::mime;
let mut headers = rama_http_types::HeaderMap::new();
headers.typed_insert(
Accept(non_empty_smallvec![
QualityValue::from(mime::TEXT_HTML),
QualityValue::from("application/xhtml+xml".parse::<mime::Mime>().unwrap()),
QualityValue::new(
mime::TEXT_XML,
900.into()
),
QualityValue::from("image/webp".parse::<mime::Mime>().unwrap()),
QualityValue::new(
mime::STAR_STAR,
800.into()
),
])
);Tuple Fields§
§0: NonEmptySmallVec<7, QualityValue<Mime>>Implementations§
Source§impl Accept
impl Accept
pub fn new_from_mime(mime: Mime) -> Self
Sourcepub fn sort_quality_values(&mut self)
pub fn sort_quality_values(&mut self)
Sort (stable) the inner quality values by quality.
Trait Implementations§
impl Eq for Accept
Source§impl HeaderDecode for Accept
impl HeaderDecode for Accept
Source§fn decode<'i, I>(values: &mut I) -> Result<Self, Error>where
I: Iterator<Item = &'i HeaderValue>,
fn decode<'i, I>(values: &mut I) -> Result<Self, Error>where
I: Iterator<Item = &'i HeaderValue>,
Decode this type from an iterator of
HeaderValues.Source§impl HeaderEncode for Accept
impl HeaderEncode for Accept
Source§fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
Encode this type to a
HeaderValue, and add it to a container
which has HeaderValue type as each element. Read moreSource§fn encode_to_value(&self) -> Option<HeaderValue>
fn encode_to_value(&self) -> Option<HeaderValue>
Encode this header to
HeaderValue. Read moreimpl StructuralPartialEq for Accept
Source§impl TypedHeader for Accept
impl TypedHeader for Accept
Source§fn name() -> &'static HeaderName
fn name() -> &'static HeaderName
The name of this header.
Auto Trait Implementations§
impl Freeze for Accept
impl RefUnwindSafe for Accept
impl Send for Accept
impl Sync for Accept
impl Unpin for Accept
impl UnsafeUnpin for Accept
impl UnwindSafe for Accept
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more