Expand description
HTTP Content headers.
These headers are used for “content negotiation”: the client shares information about which content it prefers, and the server responds by sharing which content it’s chosen to share. This enables clients to receive resources with the best available compression, in the preferred language, and more.
§Further Reading
§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");
Modules§
- accept
- Client header advertising which media types the client is able to understand.
- accept_
encoding - Client header advertising available compression algorithms.
- content_
encoding - Specify the compression algorithm.
Structs§
- Accept
- Client header advertising which media types the client is able to understand.
- Accept
Encoding - Client header advertising available compression algorithms.
- Content
Encoding - Specify the compression algorithm.
- Content
Length - The size of the entity-body, in bytes, sent to the recipient.
- Content
Location - Indicates an alternate location for the returned data.
- Content
Type - Indicate the media type of a resource’s content.
- Encoding
Proposal - A proposed
Encoding
inAcceptEncoding
. - Media
Type Proposal - A proposed Media Type for the
Accept
header.
Enums§
- Encoding
- Available compression algorithms.