hyperx/header/common/
accept_charset.rs

1use header::{Charset, QualityItem};
2
3header! {
4    /// `Accept-Charset` header, defined in
5    /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.3)
6    ///
7    /// The `Accept-Charset` header field can be sent by a user agent to
8    /// indicate what charsets are acceptable in textual response content.
9    /// This field allows user agents capable of understanding more
10    /// comprehensive or special-purpose charsets to signal that capability
11    /// to an origin server that is capable of representing information in
12    /// those charsets.
13    ///
14    /// # ABNF
15    ///
16    /// ```text
17    /// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
18    /// ```
19    ///
20    /// # Example values
21    /// * `iso-8859-5, unicode-1-1;q=0.8`
22    ///
23    /// # Examples
24    /// ```
25    /// # extern crate http;
26    /// use hyperx::header::{AcceptCharset, Charset, qitem, TypedHeaders};
27    ///
28    /// let mut headers = http::HeaderMap::new();
29    /// headers.encode(
30    ///     &AcceptCharset(vec![qitem(Charset::Us_Ascii)])
31    /// );
32    /// ```
33    /// ```
34    /// # extern crate http;
35    /// use hyperx::header::{AcceptCharset, Charset, q, QualityItem, TypedHeaders};
36    ///
37    /// let mut headers = http::HeaderMap::new();
38    /// headers.encode(
39    ///     &AcceptCharset(vec![
40    ///         QualityItem::new(Charset::Us_Ascii, q(900)),
41    ///         QualityItem::new(Charset::Iso_8859_10, q(200)),
42    ///     ])
43    /// );
44    /// ```
45    /// ```
46    /// # extern crate http;
47    /// use hyperx::header::{AcceptCharset, Charset, qitem, TypedHeaders};
48    ///
49    /// let mut headers = http::HeaderMap::new();
50    /// headers.encode(
51    ///     &AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))])
52    /// );
53    /// ```
54    (AcceptCharset, "Accept-Charset") => (QualityItem<Charset>)+
55
56    test_accept_charset {
57        // Testcase from RFC
58        test_header!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
59    }
60}
61
62standard_header!(AcceptCharset, ACCEPT_CHARSET);