headers_ext/common/
if_match.rs

1use {HeaderValue};
2use super::ETag;
3use util::FlatCsv;
4
5/// `If-Match` header, defined in
6/// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.1)
7///
8/// The `If-Match` header field makes the request method conditional on
9/// the recipient origin server either having at least one current
10/// representation of the target resource, when the field-value is "*",
11/// or having a current representation of the target resource that has an
12/// entity-tag matching a member of the list of entity-tags provided in
13/// the field-value.
14///
15/// An origin server MUST use the strong comparison function when
16/// comparing entity-tags for `If-Match`, since the client
17/// intends this precondition to prevent the method from being applied if
18/// there have been any changes to the representation data.
19///
20/// # ABNF
21///
22/// ```text
23/// If-Match = "*" / 1#entity-tag
24/// ```
25///
26/// # Example values
27///
28/// * `"xyzzy"`
29/// * "xyzzy", "r2d2xxxx", "c3piozzzz"
30///
31/// # Examples
32///
33/// ```
34/// # extern crate headers_ext as headers;
35/// use headers::IfMatch;
36///
37/// let if_match = IfMatch::any();
38/// ```
39#[derive(Clone, Debug, PartialEq, Header)]
40pub struct IfMatch(FlatCsv);
41
42impl IfMatch {
43    /// Create a new `If-Match: *` header.
44    pub fn any() -> IfMatch {
45        IfMatch(HeaderValue::from_static("*").into())
46    }
47}
48
49impl From<ETag> for IfMatch {
50    fn from(etag: ETag) -> IfMatch {
51        IfMatch(HeaderValue::from(etag.0).into())
52    }
53}
54