headers_ext/common/if_none_match.rs
1use util::{FlatCsv};
2use super::ETag;
3use {HeaderValue};
4
5/// `If-None-Match` header, defined in
6/// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.2)
7///
8/// The `If-None-Match` header field makes the request method conditional
9/// on a recipient cache or origin server either not having any current
10/// representation of the target resource, when the field-value is "*",
11/// or having a selected representation with an entity-tag that does not
12/// match any of those listed in the field-value.
13///
14/// A recipient MUST use the weak comparison function when comparing
15/// entity-tags for If-None-Match (Section 2.3.2), since weak entity-tags
16/// can be used for cache validation even if there have been changes to
17/// the representation data.
18///
19/// # ABNF
20///
21/// ```text
22/// If-None-Match = "*" / 1#entity-tag
23/// ```
24///
25/// # Example values
26///
27/// * `"xyzzy"`
28/// * `W/"xyzzy"`
29/// * `"xyzzy", "r2d2xxxx", "c3piozzzz"`
30/// * `W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"`
31/// * `*`
32///
33/// # Examples
34///
35/// ```
36/// # extern crate headers_ext as headers;
37/// use headers::IfNoneMatch;
38///
39/// let if_none_match = IfNoneMatch::any();
40/// ```
41#[derive(Clone, Debug, PartialEq, Header)]
42pub struct IfNoneMatch(FlatCsv);
43
44impl IfNoneMatch {
45 /// Create a new `If-None-Match: *` header.
46 pub fn any() -> IfNoneMatch {
47 IfNoneMatch(HeaderValue::from_static("*").into())
48 }
49}
50
51impl From<ETag> for IfNoneMatch {
52 fn from(etag: ETag) -> IfNoneMatch {
53 IfNoneMatch(HeaderValue::from(etag.0).into())
54 }
55}
56
57 /*
58 test_if_none_match {
59 test_header!(test1, vec![b"\"xyzzy\""]);
60 test_header!(test2, vec![b"W/\"xyzzy\""]);
61 test_header!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);
62 test_header!(test4, vec![b"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\""]);
63 test_header!(test5, vec![b"*"]);
64 }
65 */
66
67/*
68#[cfg(test)]
69mod tests {
70 use super::IfNoneMatch;
71 use Header;
72 use EntityTag;
73
74 #[test]
75 fn test_if_none_match() {
76 let mut if_none_match: ::Result<IfNoneMatch>;
77
78 if_none_match = Header::parse_header(&b"*".as_ref().into());
79 assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Any));
80
81 if_none_match = Header::parse_header(&b"\"foobar\", W/\"weak-etag\"".as_ref().into());
82 let mut entities: Vec<EntityTag> = Vec::new();
83 let foobar_etag = EntityTag::new(false, "foobar".to_owned());
84 let weak_etag = EntityTag::new(true, "weak-etag".to_owned());
85 entities.push(foobar_etag);
86 entities.push(weak_etag);
87 assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Items(entities)));
88 }
89}
90*/
91