use crate::CachingHeadersExt;
use trillium::{async_trait, Conn, Handler, Status};
#[derive(Debug, Clone, Copy, Default)]
pub struct Modified {
_private: (),
}
impl Modified {
pub fn new() -> Self {
Self { _private: () }
}
}
#[async_trait]
impl Handler for Modified {
async fn before_send(&self, conn: Conn) -> Conn {
match (conn.if_modified_since(), conn.last_modified()) {
(Some(if_modified_since), Some(last_modified))
if last_modified <= if_modified_since =>
{
conn.with_status(Status::NotModified)
}
_ => conn,
}
}
async fn run(&self, conn: Conn) -> Conn {
conn
}
}