http_types/content/mod.rs
1//! HTTP Content headers.
2//!
3//! These headers are used for "content negotiation": the client shares information
4//! about which content it prefers, and the server responds by sharing which
5//! content it's chosen to share. This enables clients to receive resources with the
6//! best available compression, in the preferred language, and more.
7//!
8//! # Further Reading
9//!
10//! - [MDN: Content Negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation)
11//!
12//! # Examples
13//!
14//! ```
15//! # fn main() -> http_types::Result<()> {
16//! #
17//! use http_types::content::{Accept, MediaTypeProposal};
18//! use http_types::{mime, Response};
19//!
20//! let mut accept = Accept::new();
21//! accept.push(MediaTypeProposal::new(mime::HTML, Some(0.8))?);
22//! accept.push(MediaTypeProposal::new(mime::XML, Some(0.4))?);
23//! accept.push(mime::PLAIN);
24//!
25//! let mut res = Response::new(200);
26//! let content_type = accept.negotiate(&[mime::XML])?;
27//! content_type.apply(&mut res);
28//!
29//! assert_eq!(res["Content-Type"], "application/xml;charset=utf-8");
30//! #
31//! # Ok(()) }
32//! ```
33
34pub mod accept;
35pub mod accept_encoding;
36pub mod content_encoding;
37
38mod content_length;
39mod content_location;
40mod content_type;
41mod encoding;
42mod encoding_proposal;
43mod media_type_proposal;
44
45#[doc(inline)]
46pub use accept::Accept;
47#[doc(inline)]
48pub use accept_encoding::AcceptEncoding;
49#[doc(inline)]
50pub use content_encoding::ContentEncoding;
51pub use content_length::ContentLength;
52pub use content_location::ContentLocation;
53pub use content_type::ContentType;
54pub use encoding::Encoding;
55pub use encoding_proposal::EncodingProposal;
56pub use media_type_proposal::MediaTypeProposal;