hyper_sync/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 /// use hyper_sync::header::{Headers, IfMatch};
34 ///
35 /// let mut headers = Headers::new();
36 /// headers.set(IfMatch::Any);
37 /// ```
38 ///
39 /// ```
40 /// use hyper_sync::header::{Headers, IfMatch, EntityTag};
41 ///
42 /// let mut headers = Headers::new();
43 /// headers.set(
44 /// IfMatch::Items(vec![
45 /// EntityTag::new(false, "xyzzy".to_owned()),
46 /// EntityTag::new(false, "foobar".to_owned()),
47 /// EntityTag::new(false, "bazquux".to_owned()),
48 /// ])
49 /// );
50 /// ```
51 (IfMatch, "If-Match") => {Any / (EntityTag)+}
52
53 test_if_match {
54 test_header!(
55 test1,
56 vec![b"\"xyzzy\""],
57 Some(HeaderField::Items(
58 vec![EntityTag::new(false, "xyzzy".to_owned())])));
59 test_header!(
60 test2,
61 vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
62 Some(HeaderField::Items(
63 vec![EntityTag::new(false, "xyzzy".to_owned()),
64 EntityTag::new(false, "r2d2xxxx".to_owned()),
65 EntityTag::new(false, "c3piozzzz".to_owned())])));
66 test_header!(test3, vec![b"*"], Some(IfMatch::Any));
67 }
68}
69
70bench_header!(star, IfMatch, { vec![b"*".to_vec()] });
71bench_header!(single , IfMatch, { vec![b"\"xyzzy\"".to_vec()] });
72bench_header!(multi, IfMatch,
73 { vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"".to_vec()] });