hyperx/header/common/
if_match.rs

1use header::EntityTag;
2
3header! {
4    /// `If-Match` header, defined in
5    /// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.1)
6    ///
7    /// The `If-Match` header field makes the request method conditional on
8    /// the recipient origin server either having at least one current
9    /// representation of the target resource, when the field-value is "*",
10    /// or having a current representation of the target resource that has an
11    /// entity-tag matching a member of the list of entity-tags provided in
12    /// the field-value.
13    ///
14    /// An origin server MUST use the strong comparison function when
15    /// comparing entity-tags for `If-Match`, since the client
16    /// intends this precondition to prevent the method from being applied if
17    /// there have been any changes to the representation data.
18    ///
19    /// # ABNF
20    ///
21    /// ```text
22    /// If-Match = "*" / 1#entity-tag
23    /// ```
24    ///
25    /// # Example values
26    ///
27    /// * `"xyzzy"`
28    /// * "xyzzy", "r2d2xxxx", "c3piozzzz"
29    ///
30    /// # Examples
31    ///
32    /// ```
33    /// # extern crate http;
34    /// use hyperx::header::{IfMatch, TypedHeaders};
35    ///
36    /// let mut headers = http::HeaderMap::new();
37    /// headers.encode(&IfMatch::Any);
38    /// ```
39    ///
40    /// ```
41    /// # extern crate http;
42    /// use hyperx::header::{IfMatch, EntityTag, TypedHeaders};
43    ///
44    /// let mut headers = http::HeaderMap::new();
45    /// headers.encode(
46    ///     &IfMatch::Items(vec![
47    ///         EntityTag::new(false, "xyzzy".to_owned()),
48    ///         EntityTag::new(false, "foobar".to_owned()),
49    ///         EntityTag::new(false, "bazquux".to_owned()),
50    ///     ])
51    /// );
52    /// ```
53    (IfMatch, "If-Match") => {Any / (EntityTag)+}
54
55    test_if_match {
56        test_header!(
57            test1,
58            vec![b"\"xyzzy\""],
59            Some(HeaderField::Items(
60                vec![EntityTag::new(false, "xyzzy".to_owned())])));
61        test_header!(
62            test2,
63            vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
64            Some(HeaderField::Items(
65                vec![EntityTag::new(false, "xyzzy".to_owned()),
66                     EntityTag::new(false, "r2d2xxxx".to_owned()),
67                     EntityTag::new(false, "c3piozzzz".to_owned())])));
68        test_header!(test3, vec![b"*"], Some(IfMatch::Any));
69    }
70}
71
72bench_header!(star, IfMatch, { vec![b"*".to_vec()] });
73bench_header!(single , IfMatch, { vec![b"\"xyzzy\"".to_vec()] });
74bench_header!(multi, IfMatch,
75              { vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"".to_vec()] });
76
77standard_header!(IfMatch, IF_MATCH);