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

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

Trait Implementations

impl DerefMut for Accept

fn deref_mut(&mut self) -> &mut Vec<QualityItem<Mime<Vec<(Attr, Value)>>>>

impl Deref for Accept

type Target = Vec<QualityItem<Mime<Vec<(Attr, Value)>>>>

fn deref(&self) -> &Vec<QualityItem<Mime<Vec<(Attr, Value)>>>>

impl Display for Accept

fn fmt(&self, f: &mut Formatter) -> Result<(), Error>

impl HeaderFormat for Accept

fn fmt_header(&self, f: &mut Formatter) -> Result<(), Error>

impl Header for Accept

fn header_name() -> &'static str

fn parse_header(raw: &[Vec<u8>]) -> Result<Accept, Error>

Derived Implementations

impl Clone for Accept

fn clone(&self) -> Accept

impl Debug for Accept

fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>

impl PartialEq<Accept> for Accept

fn eq(&self, __arg_0: &Accept) -> bool

fn ne(&self, __arg_0: &Accept) -> bool