kutil_http/headers/
conditional.rs

1use super::{date::*, headers::*};
2
3use http::*;
4
5/// Conditional HTTP.
6///
7/// If there is not enough information we will assume that we have been modified and return true.
8pub fn modified(request_headers: &HeaderMap, response_headers: &HeaderMap) -> bool {
9    // `If-None-Match` takes precedence over `If-Modified-Since`
10
11    if let Some(if_none_match) = request_headers.if_none_match() {
12        // Note that ETagMatch::Any has a special meaning when not GET or HEAD
13
14        if if_none_match.matches(response_headers.etag().as_ref()) {
15            tracing::debug!("not modified (If-None-Match)");
16            return false;
17        }
18    }
19
20    if !modified_since(response_headers.last_modified(), request_headers.if_modified_since()) {
21        tracing::debug!("not modified (If-Modified-Since)");
22        return false;
23    }
24
25    // Note that `If-Match` and `If-Unmodified-Since` have different uses:
26    // https://stackoverflow.com/questions/2157124/http-if-none-match-vs-if-match
27
28    true
29}