[][src]Struct scrappy_http::http::header::Accept

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

  • audio/*; q=0.2, audio/basic
  • text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c

Examples

extern crate mime;
use scrappy_http::Response;
use scrappy_http::http::header::{Accept, qitem};

let mut builder = Response::Ok();

builder.set(
    Accept(vec![
        qitem(mime::TEXT_HTML),
    ])
);
extern crate mime;
use scrappy_http::Response;
use scrappy_http::http::header::{Accept, qitem};

let mut builder = Response::Ok();

builder.set(
    Accept(vec![
        qitem(mime::APPLICATION_JSON),
    ])
);
extern crate mime;
use scrappy_http::Response;
use scrappy_http::http::header::{Accept, QualityItem, q, qitem};

let mut builder = Response::Ok();

builder.set(
    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)
        ),
    ])
);

Methods

impl Accept[src]

pub fn star() -> Accept[src]

A constructor to easily create Accept: */*.

pub fn json() -> Accept[src]

A constructor to easily create Accept: application/json.

pub fn text() -> Accept[src]

A constructor to easily create Accept: text/*.

pub fn image() -> Accept[src]

A constructor to easily create Accept: image/*.

Trait Implementations

impl Clone for Accept[src]

impl Debug for Accept[src]

impl Deref for Accept[src]

type Target = Vec<QualityItem<Mime>>

The resulting type after dereferencing.

impl DerefMut for Accept[src]

impl Display for Accept[src]

impl Header for Accept[src]

impl IntoHeaderValue for Accept[src]

type Error = InvalidHeaderValue

The type returned in the event of a conversion error.

impl PartialEq<Accept> for Accept[src]

impl StructuralPartialEq for Accept[src]

Auto Trait Implementations

impl RefUnwindSafe for Accept

impl Send for Accept

impl Sync for Accept

impl Unpin for Accept

impl UnwindSafe for Accept

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,