Skip to main content

actix_web/http/header/
if_modified_since.rs

1use super::{HttpDate, IF_MODIFIED_SINCE};
2
3crate::http::header::common_header! {
4    /// `If-Modified-Since` header, defined
5    /// in [RFC 7232 ยง3.3](https://datatracker.ietf.org/doc/html/rfc7232#section-3.3)
6    ///
7    /// The `If-Modified-Since` header field makes a GET or HEAD request
8    /// method conditional on the selected representation's modification date
9    /// being more recent than the date provided in the field-value.
10    /// Transfer of the selected representation's data is avoided if that
11    /// data has not changed.
12    ///
13    /// # Note
14    /// This is a request header used for cache validation. Servers should not send
15    /// `If-Modified-Since` in responses; use [`LastModified`](super::LastModified) / the
16    /// `Last-Modified` header instead.
17    ///
18    /// # ABNF
19    /// ```plain
20    /// If-Modified-Since = HTTP-date
21    /// ```
22    ///
23    /// # Example Values
24    /// * `Sat, 29 Oct 1994 19:43:31 GMT`
25    ///
26    /// # Examples
27    ///
28    /// ```
29    /// use std::time::{SystemTime, Duration};
30    /// use actix_web::{http::header::IfModifiedSince, test};
31    ///
32    /// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
33    /// let req = test::TestRequest::default()
34    ///     .insert_header(IfModifiedSince(modified.into()))
35    ///     .to_http_request();
36    /// # let _ = req;
37    /// ```
38    (IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate]
39
40    test_parse_and_format {
41        // Test case from RFC
42        crate::http::header::common_header_test!(test1, [b"Sat, 29 Oct 1994 19:43:31 GMT"]);
43    }
44}