Struct trillium_http_types::content::Accept [−][src]
pub struct Accept { /* fields omitted */ }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.
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])?; res.insert_header(&content_type, &content_type); assert_eq!(res["Content-Type"], "application/xml;charset=utf-8");
Implementations
Create an instance of Accept from a Headers instance.
Push a directive into the list of entries.
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.
An iterator visiting all entries.
Trait Implementations
Access the header’s name.
Access the header’s value.
Auto Trait Implementations
impl RefUnwindSafe for Acceptimpl UnwindSafe for Accept