headers_ext/common/etag.rs
1use util::EntityTag;
2
3/// `ETag` header, defined in [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.3)
4///
5/// The `ETag` header field in a response provides the current entity-tag
6/// for the selected representation, as determined at the conclusion of
7/// handling the request. An entity-tag is an opaque validator for
8/// differentiating between multiple representations of the same
9/// resource, regardless of whether those multiple representations are
10/// due to resource state changes over time, content negotiation
11/// resulting in multiple representations being valid at the same time,
12/// or both. An entity-tag consists of an opaque quoted string, possibly
13/// prefixed by a weakness indicator.
14///
15/// # ABNF
16///
17/// ```text
18/// ETag = entity-tag
19/// ```
20///
21/// # Example values
22///
23/// * `"xyzzy"`
24/// * `W/"xyzzy"`
25/// * `""`
26///
27/// # Examples
28///
29#[derive(Clone, Debug, PartialEq, Eq, Header)]
30#[header(name_const = "ETAG")]
31pub struct ETag(pub(super) EntityTag);
32
33 /*
34 test_etag {
35 // From the RFC
36 test_header!(test1,
37 vec![b"\"xyzzy\""],
38 Some(ETag(EntityTag::new(false, "xyzzy".to_owned()))));
39 test_header!(test2,
40 vec![b"W/\"xyzzy\""],
41 Some(ETag(EntityTag::new(true, "xyzzy".to_owned()))));
42 test_header!(test3,
43 vec![b"\"\""],
44 Some(ETag(EntityTag::new(false, "".to_owned()))));
45 // Own tests
46 test_header!(test4,
47 vec![b"\"foobar\""],
48 Some(ETag(EntityTag::new(false, "foobar".to_owned()))));
49 test_header!(test5,
50 vec![b"\"\""],
51 Some(ETag(EntityTag::new(false, "".to_owned()))));
52 test_header!(test6,
53 vec![b"W/\"weak-etag\""],
54 Some(ETag(EntityTag::new(true, "weak-etag".to_owned()))));
55 test_header!(test7,
56 vec![b"W/\"\x65\x62\""],
57 Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_owned()))));
58 test_header!(test8,
59 vec![b"W/\"\""],
60 Some(ETag(EntityTag::new(true, "".to_owned()))));
61 test_header!(test9,
62 vec![b"no-dquotes"],
63 None::<ETag>);
64 test_header!(test10,
65 vec![b"w/\"the-first-w-is-case-sensitive\""],
66 None::<ETag>);
67 test_header!(test11,
68 vec![b""],
69 None::<ETag>);
70 test_header!(test12,
71 vec![b"\"unmatched-dquotes1"],
72 None::<ETag>);
73 test_header!(test13,
74 vec![b"unmatched-dquotes2\""],
75 None::<ETag>);
76 test_header!(test14,
77 vec![b"matched-\"dquotes\""],
78 None::<ETag>);
79 test_header!(test15,
80 vec![b"\""],
81 None::<ETag>);
82 }
83 */
84