cogo_http/header/common/
accept_charset.rs

1use crate::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    /// ```plain
16    /// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
17    /// ```
18    ///
19    /// # Example values
20    /// * `iso-8859-5, unicode-1-1;q=0.8`
21    ///
22    /// # Examples
23    /// ```
24    /// use cogo_http::header::{Headers, AcceptCharset, Charset, qitem};
25    ///
26    /// let mut headers = Headers::new();
27    /// headers.set(
28    ///     AcceptCharset(vec![qitem(Charset::Us_Ascii)])
29    /// );
30    /// ```
31    /// ```
32    /// use cogo_http::header::{Headers, AcceptCharset, Charset, Quality, QualityItem};
33    ///
34    /// let mut headers = Headers::new();
35    /// headers.set(
36    ///     AcceptCharset(vec![
37    ///         QualityItem::new(Charset::Us_Ascii, Quality(900)),
38    ///         QualityItem::new(Charset::Iso_8859_10, Quality(200)),
39    ///     ])
40    /// );
41    /// ```
42    /// ```
43    /// use cogo_http::header::{Headers, AcceptCharset, Charset, qitem};
44    ///
45    /// let mut headers = Headers::new();
46    /// headers.set(
47    ///     AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))])
48    /// );
49    /// ```
50    (AcceptCharset, "Accept-Charset") => (QualityItem<Charset>)+
51
52    test_accept_charset {
53        /// Testcase from RFC
54        test_header!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
55    }
56}