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    /// # ABNF
14    /// ```plain
15    /// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
16    /// ```
17    ///
18    /// # Example Values
19    /// * `iso-8859-5, unicode-1-1;q=0.8`
20    ///
21    /// # Examples
22    /// ```
23    /// use actix_web::HttpResponse;
24    /// use actix_web::http::header::{AcceptCharset, Charset, QualityItem};
25    ///
26    /// let mut builder = HttpResponse::Ok();
27    /// builder.insert_header(
28    ///     AcceptCharset(vec![QualityItem::max(Charset::Us_Ascii)])
29    /// );
30    /// ```
31    ///
32    /// ```
33    /// use actix_web::HttpResponse;
34    /// use actix_web::http::header::{AcceptCharset, Charset, q, QualityItem};
35    ///
36    /// let mut builder = HttpResponse::Ok();
37    /// builder.insert_header(
38    ///     AcceptCharset(vec![
39    ///         QualityItem::new(Charset::Us_Ascii, q(0.9)),
40    ///         QualityItem::new(Charset::Iso_8859_10, q(0.2)),
41    ///     ])
42    /// );
43    /// ```
44    ///
45    /// ```
46    /// use actix_web::HttpResponse;
47    /// use actix_web::http::header::{AcceptCharset, Charset, QualityItem};
48    ///
49    /// let mut builder = HttpResponse::Ok();
50    /// builder.insert_header(
51    ///     AcceptCharset(vec![QualityItem::max(Charset::Ext("utf-8".to_owned()))])
52    /// );
53    /// ```
54    ///
55    /// [RFC 7231 §5.3.3]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.3
56    (AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)*
57
58    test_parse_and_format {
59        // Test case from RFC
60        common_header_test!(test1, [b"iso-8859-5, unicode-1-1;q=0.8"]);
61    }
62}