hyperx/header/common/transfer_encoding.rs
1use header::Encoding;
2
3header! {
4 /// `Transfer-Encoding` header, defined in
5 /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-3.3.1)
6 ///
7 /// The `Transfer-Encoding` header field lists the transfer coding names
8 /// corresponding to the sequence of transfer codings that have been (or
9 /// will be) applied to the payload body in order to form the message
10 /// body.
11 ///
12 /// Note that setting this header will *remove* any previously set
13 /// `Content-Length` header, in accordance with
14 /// [RFC7230](http://tools.ietf.org/html/rfc7230#section-3.3.2):
15 ///
16 /// > A sender MUST NOT send a Content-Length header field in any message
17 /// > that contains a Transfer-Encoding header field.
18 ///
19 /// # ABNF
20 ///
21 /// ```text
22 /// Transfer-Encoding = 1#transfer-coding
23 /// ```
24 ///
25 /// # Example values
26 ///
27 /// * `gzip, chunked`
28 ///
29 /// # Example
30 ///
31 /// ```
32 /// # extern crate http;
33 /// use hyperx::header::{TransferEncoding, Encoding, TypedHeaders};
34 ///
35 /// let mut headers = http::HeaderMap::new();
36 /// headers.encode(
37 /// &TransferEncoding(vec![
38 /// Encoding::Gzip,
39 /// Encoding::Chunked,
40 /// ])
41 /// );
42 /// ```
43 (TransferEncoding, "Transfer-Encoding") => (Encoding)+
44
45 transfer_encoding {
46 test_header!(
47 test1,
48 vec![b"gzip, chunked"],
49 Some(HeaderField(
50 vec![Encoding::Gzip, Encoding::Chunked]
51 )));
52 // Issue: #683
53 test_header!(
54 test2,
55 vec![b"chunked", b"chunked"],
56 Some(HeaderField(
57 vec![Encoding::Chunked, Encoding::Chunked]
58 )));
59
60 }
61}
62
63impl TransferEncoding {
64 /// Constructor for the most common Transfer-Encoding, `chunked`.
65 pub fn chunked() -> TransferEncoding {
66 TransferEncoding(vec![Encoding::Chunked])
67 }
68}
69
70bench_header!(normal, TransferEncoding, { vec![b"chunked, gzip".to_vec()] });
71bench_header!(ext, TransferEncoding, { vec![b"ext".to_vec()] });
72
73standard_header!(TransferEncoding, TRANSFER_ENCODING);