tower_embed_core/headers/
last_modified.rs1use std::time::{Duration, SystemTime};
2
3#[derive(Clone, Copy, Debug)]
5pub struct LastModified(pub SystemTime);
6
7impl LastModified {
8 pub fn from_unix_timestamp(seconds: u64) -> Option<Self> {
10 SystemTime::UNIX_EPOCH
11 .checked_add(Duration::from_secs(seconds))
12 .map(Self)
13 }
14}
15
16impl super::Header for LastModified {
17 fn header_name() -> http::HeaderName {
18 http::header::LAST_MODIFIED
19 }
20
21 fn decode(value: &http::HeaderValue) -> Option<Self> {
22 let value_str = value.to_str().ok()?;
23 let http_date = httpdate::parse_http_date(value_str).ok()?;
24 Some(LastModified(http_date))
25 }
26
27 fn encode(self) -> http::HeaderValue {
28 let value_string = httpdate::fmt_http_date(self.0);
29 http::HeaderValue::from_str(&value_string).unwrap()
30 }
31}