trillium_caching_headers/
modified.rs1use crate::CachingHeadersExt;
2use trillium::{Conn, Handler, Status};
3
4#[derive(Debug, Clone, Copy, Default)]
9pub struct Modified {
10 _private: (),
11}
12
13impl Modified {
14 pub fn new() -> Self {
16 Self { _private: () }
17 }
18}
19
20impl Handler for Modified {
21 async fn before_send(&self, conn: Conn) -> Conn {
22 match (conn.if_modified_since(), conn.last_modified()) {
23 (Some(if_modified_since), Some(last_modified))
24 if last_modified <= if_modified_since =>
25 {
26 conn.with_status(Status::NotModified)
27 }
28
29 _ => conn,
30 }
31 }
32
33 async fn run(&self, conn: Conn) -> Conn {
34 conn
35 }
36}