tower_embed_core/headers/
if_modified_since.rs1use std::time::SystemTime;
2
3use crate::headers::LastModified;
4
5pub struct IfModifiedSince(SystemTime);
7
8impl IfModifiedSince {
9 pub fn condition_passes(&self, last_modified: &LastModified) -> bool {
10 last_modified.0 > self.0
11 }
12}
13
14impl super::Header for IfModifiedSince {
15 fn header_name() -> http::HeaderName {
16 http::header::IF_MODIFIED_SINCE
17 }
18
19 fn decode(value: &http::HeaderValue) -> Option<Self> {
20 let value_str = value.to_str().ok()?;
21 let http_date = httpdate::parse_http_date(value_str).ok()?;
22 Some(IfModifiedSince(http_date))
23 }
24
25 fn encode(self) -> http::HeaderValue {
26 let value_string = httpdate::fmt_http_date(self.0);
27 http::HeaderValue::from_str(&value_string).unwrap()
28 }
29}