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/basic
  • text/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)
        ),
    ])
);

Tuple Fields

0: Vec<QualityItem<Mime>>

Implementations

Construct Accept: */*.

Construct Accept: application/json.

Construct Accept: text/*.

Construct Accept: image/*.

Construct Accept: text/html.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Formats the value using the given formatter. Read more

Returns the name of the header field

Parse a header

The type returned in the event of a conversion error.

Try to convert value to a HeaderValue.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more