Skip to main content

actix_web/http/header/
accept_charset.rs

1use super::{common_header, Charset, QualityItem, ACCEPT_CHARSET};
2
3common_header! {
4    /// `Accept-Charset` header, defined in [RFC 7231 §5.3.3].
5    ///
6    /// The `Accept-Charset` header field can be sent by a user agent to
7    /// indicate what charsets are acceptable in textual response content.
8    /// This field allows user agents capable of understanding more
9    /// comprehensive or special-purpose charsets to signal that capability
10    /// to an origin server that is capable of representing information in
11    /// those charsets.
12    ///
13    /// # Note
14    /// This is a request header. Servers should not send `Accept-Charset` in responses; to
15    /// describe the response body's charset, set an appropriate `Content-Type` header instead.
16    ///
17    /// # ABNF
18    /// ```plain
19    /// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
20    /// ```
21    ///
22    /// # Example Values
23    /// * `iso-8859-5, unicode-1-1;q=0.8`
24    ///
25    /// # Examples
26    /// ```
27    /// use actix_web::{http::header::{AcceptCharset, Charset, QualityItem}, test};
28    ///
29    /// let req = test::TestRequest::default()
30    ///     .insert_header(AcceptCharset(vec![QualityItem::max(Charset::Us_Ascii)]))
31    ///     .to_http_request();
32    /// # let _ = req;
33    /// ```
34    ///
35    /// ```
36    /// use actix_web::{http::header::{AcceptCharset, Charset, q, QualityItem}, test};
37    ///
38    /// let req = test::TestRequest::default()
39    ///     .insert_header(AcceptCharset(vec![
40    ///         QualityItem::new(Charset::Us_Ascii, q(0.9)),
41    ///         QualityItem::new(Charset::Iso_8859_10, q(0.2)),
42    ///     ]))
43    ///     .to_http_request();
44    /// # let _ = req;
45    /// ```
46    ///
47    /// ```
48    /// use actix_web::{http::header::{AcceptCharset, Charset, QualityItem}, test};
49    ///
50    /// let req = test::TestRequest::default()
51    ///     .insert_header(AcceptCharset(vec![QualityItem::max(Charset::Ext("utf-8".to_owned()))]))
52    ///     .to_http_request();
53    /// # let _ = req;
54    /// ```
55    ///
56    /// [RFC 7231 §5.3.3]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.3
57    (AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)*
58
59    test_parse_and_format {
60        // Test case from RFC
61        common_header_test!(test1, [b"iso-8859-5, unicode-1-1;q=0.8"]);
62    }
63}