Struct http_stub::header::Accept
[−]
[src]
pub struct Accept(pub Vec<QualityItem<Mime<Vec<(Attr, Value)>>>>);
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/basic
(*
value won't parse correctly)text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c
Examples
use hyper::header::{Headers, Accept, qitem}; use hyper::mime::{Mime, TopLevel, SubLevel}; let mut headers = Headers::new(); headers.set( Accept(vec![ qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])), ]) );
use hyper::header::{Headers, Accept, qitem}; use hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value}; let mut headers = Headers::new(); headers.set( Accept(vec![ qitem(Mime(TopLevel::Application, SubLevel::Json, vec![(Attr::Charset, Value::Utf8)])), ]) );
use hyper::header::{Headers, Accept, QualityItem, Quality, qitem}; use hyper::mime::{Mime, TopLevel, SubLevel}; let mut headers = Headers::new(); headers.set( Accept(vec![ qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])), qitem(Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_owned()), vec![])), QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]), Quality(900)), qitem(Mime(TopLevel::Image, SubLevel::Ext("webp".to_owned()), vec![])), QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), Quality(800)) ]) );
Notes
- Using always Mime types to represent
media-range
differs from the ABNF. - FIXME:
accept-ext
is not supported.