1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use rama_core::telemetry::tracing;
use rama_http_types::HeaderValue;
use crate::util::HttpDate;
use std::time::SystemTime;
/// `Last-Modified` header, defined in
/// [RFC7232](https://datatracker.ietf.org/doc/html/rfc7232#section-2.2)
///
/// The `Last-Modified` header field in a response provides a timestamp
/// indicating the date and time at which the origin server believes the
/// selected representation was last modified, as determined at the
/// conclusion of handling the request.
///
/// # ABNF
///
/// ```text
/// Expires = HTTP-date
/// ```
///
/// # Example values
///
/// * `Sat, 29 Oct 1994 19:43:31 GMT`
///
/// # Example
///
/// ```
/// use rama_http_headers::LastModified;
/// use std::time::Duration;
/// use rama_utils::time::now_system_time;
///
/// let modified = LastModified::from(
/// now_system_time() - Duration::from_hours(24)
/// );
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LastModified(pub(super) HttpDate);
impl crate::TypedHeader for LastModified {
fn name() -> &'static ::rama_http_types::header::HeaderName {
&::rama_http_types::header::LAST_MODIFIED
}
}
impl crate::HeaderDecode for LastModified {
fn decode<'i, I>(values: &mut I) -> Result<Self, crate::Error>
where
I: Iterator<Item = &'i ::rama_http_types::header::HeaderValue>,
{
crate::util::TryFromValues::try_from_values(values).map(LastModified)
}
}
impl crate::HeaderEncode for LastModified {
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
match HeaderValue::try_from(&self.0) {
Ok(value) => values.extend(::std::iter::once(value)),
Err(err) => {
tracing::debug!("failed to encode last-modified value as header: {err}");
}
}
}
}
impl From<SystemTime> for LastModified {
fn from(time: SystemTime) -> Self {
Self(time.into())
}
}
impl From<LastModified> for SystemTime {
fn from(date: LastModified) -> Self {
date.0.into()
}
}