requiem_http/header/common/
if_match.rs

1use crate::header::{EntityTag, IF_MATCH};
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    /// ```rust
33    /// use requiem_http::Response;
34    /// use requiem_http::http::header::IfMatch;
35    ///
36    /// let mut builder = Response::Ok();
37    /// builder.set(IfMatch::Any);
38    /// ```
39    ///
40    /// ```rust
41    /// use requiem_http::Response;
42    /// use requiem_http::http::header::{IfMatch, EntityTag};
43    ///
44    /// let mut builder = Response::Ok();
45    /// builder.set(
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}