hyperx/header/common/
te.rs

1use header::{Encoding, QualityItem};
2
3header! {
4    /// `TE` header, defined in
5    /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-4.3)
6    ///
7    /// As RFC7230 states, "The "TE" header field in a request indicates what transfer codings,
8    /// besides chunked, the client is willing to accept in response, and
9    /// whether or not the client is willing to accept trailer fields in a
10    /// chunked transfer coding."
11    ///
12    /// For HTTP/1.1 compliant clients `chunked` transfer codings are assumed to be acceptable and
13    /// so should never appear in this header.
14    ///
15    /// # ABNF
16    ///
17    /// ```text
18    /// TE        = "TE" ":" #( t-codings )
19    /// t-codings = "trailers" | ( transfer-extension [ accept-params ] )
20    /// ```
21    ///
22    /// # Example values
23    /// * `trailers`
24    /// * `trailers, deflate;q=0.5`
25    /// * ``
26    ///
27    /// # Examples
28    ///
29    /// ```
30    /// # extern crate http;
31    /// use hyperx::header::{Te, Encoding, qitem, TypedHeaders};
32    ///
33    /// let mut headers = http::HeaderMap::new();
34    /// headers.encode(
35    ///     &Te(vec![qitem(Encoding::Trailers)])
36    /// );
37    /// ```
38    ///
39    /// ```
40    /// # extern crate http;
41    /// use hyperx::header::{Te, Encoding, qitem, TypedHeaders};
42    ///
43    /// let mut headers = http::HeaderMap::new();
44    /// headers.encode(
45    ///     &Te(vec![
46    ///         qitem(Encoding::Trailers),
47    ///         qitem(Encoding::Gzip),
48    ///         qitem(Encoding::Deflate),
49    ///     ])
50    /// );
51    /// ```
52    ///
53    /// ```
54    /// # extern crate http;
55    /// use hyperx::header::{Te, Encoding, QualityItem, q, qitem, TypedHeaders};
56    ///
57    /// let mut headers = http::HeaderMap::new();
58    /// headers.encode(
59    ///     &Te(vec![
60    ///         qitem(Encoding::Trailers),
61    ///         QualityItem::new(Encoding::Gzip, q(600)),
62    ///         QualityItem::new(Encoding::EncodingExt("*".to_owned()), q(0)),
63    ///     ])
64    /// );
65    /// ```
66    (Te, "TE") => (QualityItem<Encoding>)*
67
68    test_te {
69        // From the RFC
70        test_header!(test1, vec![b"trailers"]);
71        test_header!(test2, vec![b"trailers, deflate;q=0.5"]);
72        test_header!(test3, vec![b""]);
73    }
74}
75
76standard_header!(Te, TE);