Skip to content

Commit af526db

Browse files
committed
Update docs
1 parent 3cc6ae8 commit af526db

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/content/accept.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Client header advertising available compression algorithms.
1+
//! Client header advertising which media types the client is able to understand
22
33
use crate::content::{ContentType, MediaTypeProposal};
44
use crate::headers::{HeaderName, HeaderValue, Headers, ToHeaderValues, ACCEPT};
@@ -9,11 +9,19 @@ use std::fmt::{self, Debug, Write};
99
use std::option;
1010
use std::slice;
1111

12-
/// Client header advertising available compression algorithms.
12+
/// Client header advertising which media types the client is able to understand
13+
///
14+
/// Using content negotiation, the server then selects one of the proposals, uses
15+
/// it and informs the client of its choice with the `Content-Type` response
16+
/// header. Browsers set adequate values for this header depending on the context
17+
/// where the request is done: when fetching a CSS stylesheet a different value
18+
/// is set for the request than when fetching an image, video or a script.
19+
///
20+
/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding)
1321
///
1422
/// # Specifications
1523
///
16-
/// - [RFC 7231, section 5.3.4: Accept-Encoding](https://tools.ietf.org/html/rfc7231#section-5.3.4)
24+
/// - [RFC 7231, section 5.3.2: Accept](https://tools.ietf.org/html/rfc7231#section-5.3.2)
1725
///
1826
/// # Examples
1927
///

src/content/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
//! about which content it prefers, and the server responds by sharing which
55
//! content it's chosen to share. This enables clients to receive resources with the
66
//! best available compression, in the preferred language, and more.
7+
//!
8+
//! # Examples
9+
//!
10+
//! ```
11+
//! # fn main() -> http_types::Result<()> {
12+
//! #
13+
//! use http_types::content::{Accept, MediaTypeProposal};
14+
//! use http_types::{mime, Response};
15+
//!
16+
//! let mut accept = Accept::new();
17+
//! accept.push(MediaTypeProposal::new(mime::HTML, Some(0.8))?);
18+
//! accept.push(MediaTypeProposal::new(mime::XML, Some(0.4))?);
19+
//! accept.push(MediaTypeProposal::new(mime::PLAIN, None)?);
20+
//!
21+
//! let mut res = Response::new(200);
22+
//! let content_type = accept.negotiate(&[mime::XML])?;
23+
//! content_type.apply(&mut res);
24+
//!
25+
//! assert_eq!(res["Content-Type"], "application/xml;charset=utf-8");
26+
//! #
27+
//! # Ok(()) }
28+
//! ```
729
830
pub mod accept;
931
pub mod accept_encoding;
@@ -16,6 +38,7 @@ mod encoding;
1638
mod encoding_proposal;
1739
mod media_type_proposal;
1840

41+
#[doc(inline)]
1942
pub use accept::Accept;
2043
#[doc(inline)]
2144
pub use accept_encoding::AcceptEncoding;

0 commit comments

Comments
 (0)