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