Struct hyper::header::Accept [] [src]

pub struct Accept(pub Vec<QualityItem<Mime>>);

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

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