cogo_http/header/common/if_match.rs
1use crate::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 /// ```plain
21 /// If-Match = "*" / 1#entity-tag
22 /// ```
23 ///
24 /// # Example values
25 /// * `"xyzzy"`
26 /// * "xyzzy", "r2d2xxxx", "c3piozzzz"
27 ///
28 /// # Examples
29 /// ```
30 /// use cogo_http::header::{Headers, IfMatch};
31 ///
32 /// let mut headers = Headers::new();
33 /// headers.set(IfMatch::Any);
34 /// ```
35 /// ```
36 /// use cogo_http::header::{Headers, IfMatch, EntityTag};
37 ///
38 /// let mut headers = Headers::new();
39 /// headers.set(
40 /// IfMatch::Items(vec![
41 /// EntityTag::new(false, "xyzzy".to_owned()),
42 /// EntityTag::new(false, "foobar".to_owned()),
43 /// EntityTag::new(false, "bazquux".to_owned()),
44 /// ])
45 /// );
46 /// ```
47 (IfMatch, "If-Match") => {Any / (EntityTag)+}
48
49 test_if_match {
50 test_header!(
51 test1,
52 vec![b"\"xyzzy\""],
53 Some(HeaderField::Items(
54 vec![EntityTag::new(false, "xyzzy".to_owned())])));
55 test_header!(
56 test2,
57 vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
58 Some(HeaderField::Items(
59 vec![EntityTag::new(false, "xyzzy".to_owned()),
60 EntityTag::new(false, "r2d2xxxx".to_owned()),
61 EntityTag::new(false, "c3piozzzz".to_owned())])));
62 test_header!(test3, vec![b"*"], Some(IfMatch::Any));
63 }
64}
65
66bench_header!(star, IfMatch, { vec![b"*".to_vec()] });
67bench_header!(single , IfMatch, { vec![b"\"xyzzy\"".to_vec()] });
68bench_header!(multi, IfMatch,
69 { vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"".to_vec()] });