pub struct Accept { /* private fields */ }
Expand description

Client header advertising which media types the client is able to understand.

Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending on the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.

MDN Documentation

Specifications

Examples

use http_types::content::{Accept, MediaTypeProposal};
use http_types::{mime, Response};

let mut accept = Accept::new();
accept.push(MediaTypeProposal::new(mime::HTML, Some(0.8))?);
accept.push(MediaTypeProposal::new(mime::XML, Some(0.4))?);
accept.push(mime::PLAIN);

let mut res = Response::new(200);
let content_type = accept.negotiate(&[mime::XML])?;
content_type.apply(&mut res);

assert_eq!(res["Content-Type"], "application/xml;charset=utf-8");

Implementations

Create a new instance of Accept.

Create an instance of Accept from a Headers instance.

Push a directive into the list of entries.

Returns true if a wildcard directive was passed.

Set the wildcard directive.

Sort the header directives by weight.

Headers with a higher q= value will be returned first. If two directives have the same weight, the directive that was declared later will be returned first.

Determine the most suitable Content-Type encoding.

Errors

If no suitable encoding is found, an error with the status of 406 will be returned.

Sets the Accept-Encoding header.

Get the HeaderName.

Get the HeaderValue.

An iterator visiting all entries.

An iterator visiting all entries.

Trait Implementations

Formats the value using the given formatter. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Returned iterator over header values which this type may correspond to.

Converts this object to an iterator of resolved HeaderValues.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

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.