actix_web/http/header/if_match.rs
1use super::{common_header, EntityTag, IF_MATCH};
2
3common_header! {
4 /// `If-Match` header, defined
5 /// in [RFC 7232 ยง3.1](https://datatracker.ietf.org/doc/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 actix_web::HttpResponse;
31 /// use actix_web::http::header::IfMatch;
32 ///
33 /// let mut builder = HttpResponse::Ok();
34 /// builder.insert_header(IfMatch::Any);
35 /// ```
36 ///
37 /// ```
38 /// use actix_web::HttpResponse;
39 /// use actix_web::http::header::{IfMatch, EntityTag};
40 ///
41 /// let mut builder = HttpResponse::Ok();
42 /// builder.insert_header(
43 /// IfMatch::Items(vec![
44 /// EntityTag::new(false, "xyzzy".to_owned()),
45 /// EntityTag::new(false, "foobar".to_owned()),
46 /// EntityTag::new(false, "bazquux".to_owned()),
47 /// ])
48 /// );
49 /// ```
50 (IfMatch, IF_MATCH) => {Any / (EntityTag)+}
51
52 test_parse_and_format {
53 crate::http::header::common_header_test!(
54 test1,
55 [b"\"xyzzy\""],
56 Some(HeaderField::Items(
57 vec![EntityTag::new_strong("xyzzy".to_owned())])));
58
59 crate::http::header::common_header_test!(
60 test2,
61 [b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
62 Some(HeaderField::Items(
63 vec![EntityTag::new_strong("xyzzy".to_owned()),
64 EntityTag::new_strong("r2d2xxxx".to_owned()),
65 EntityTag::new_strong("c3piozzzz".to_owned())])));
66 crate::http::header::common_header_test!(test3, [b"*"], Some(IfMatch::Any));
67 }
68}