Struct actix_web::http::header::Accept [−][src]
pub struct Accept(pub Vec<QualityItem<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 actix_web::HttpResponse; use actix_web::http::header::{Accept, qitem}; let mut builder = HttpResponse::Ok(); builder.insert_header( Accept(vec![ qitem(mime::TEXT_HTML), ]) );
use actix_web::HttpResponse; use actix_web::http::header::{Accept, qitem}; let mut builder = HttpResponse::Ok(); builder.insert_header( Accept(vec![ qitem(mime::APPLICATION_JSON), ]) );
use actix_web::HttpResponse; use actix_web::http::header::{Accept, QualityItem, q, qitem}; let mut builder = HttpResponse::Ok(); builder.insert_header( Accept(vec![ qitem(mime::TEXT_HTML), qitem("application/xhtml+xml".parse().unwrap()), QualityItem::new( mime::TEXT_XML, q(900) ), qitem("image/webp".parse().unwrap()), QualityItem::new( mime::STAR_STAR, q(800) ), ]) );
Implementations
Returns a sorted list of mime types from highest to lowest preference, accounting for q-factor weighting and specificity.
Extracts the most preferable mime type, accounting for q-factor weighting.
If no q-factors are provided, the first mime type is chosen. Note that items without q-factors are given the maximum preference value.
Returns None if contained list is empty.
Trait Implementations
type Target = Vec<QualityItem<Mime>>
type Target = Vec<QualityItem<Mime>>The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Returns the name of the header field
Parse a header
type Error = InvalidHeaderValue
type Error = InvalidHeaderValueThe type returned in the event of a conversion error.
Try to convert value to a HeaderValue.
Auto Trait Implementations
impl RefUnwindSafe for Acceptimpl UnwindSafe for AcceptBlanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
type Error = <T as IntoHeaderValue>::Errorpub fn try_into_header_pair(
self
) -> Result<(HeaderName, HeaderValue), <T as IntoHeaderPair>::Error>type Output = T
type Output = TShould always be Self
pub fn vzip(self) -> V