about summary refs log tree commit diff
path: root/src/frontend
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-26 21:20:53 +0300
committerVika <vika@fireburn.ru>2024-08-26 21:20:53 +0300
commit2e750309983b67e5baadeb4109960e8637c1c894 (patch)
tree29c83b4b9bcadc7a9656a7acb94d13139db483c5 /src/frontend
parent703e790d63c7fb06212538f2c3f3671d59de4029 (diff)
downloadkittybox-2e750309983b67e5baadeb4109960e8637c1c894.tar.zst
Add Last-Modified header to post pages to help heuristic caching
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mod.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
index e142ee1..7ddad07 100644
--- a/src/frontend/mod.rs
+++ b/src/frontend/mod.rs
@@ -4,6 +4,7 @@ use axum::{
     http::{StatusCode, Uri},
     response::IntoResponse,
 };
+use axum_extra::headers::HeaderMapExt;
 use futures_util::FutureExt;
 use serde::Deserialize;
 use std::convert::TryInto;
@@ -270,6 +271,7 @@ pub async fn homepage<D: Storage>(
 
                 db.get_channels(&hcard_url).map(|i| i.unwrap_or_default())
             );
+
             if user.is_some() {
                 headers.insert(
                     axum::http::header::CACHE_CONTROL,
@@ -370,6 +372,26 @@ pub async fn catchall<D: Storage>(
                 );
             }
 
+            if post["type"][0].as_str() == Some("h-entry") {
+                let last_modified = post["properties"]["updated"]
+                    .as_array()
+                    .and_then(|v| v.last())
+                    .or_else(|| post["properties"]["published"]
+                        .as_array()
+                        .and_then(|v| v.last())
+                    )
+                    .and_then(serde_json::Value::as_str)
+                    .and_then(|dt| chrono::DateTime::<chrono::FixedOffset>::parse_from_rfc3339(dt).ok());
+
+                if let Some(last_modified) = last_modified {
+                    headers.typed_insert(
+                        axum_extra::headers::LastModified::from(
+                            std::time::SystemTime::from(last_modified)
+                        )
+                    );
+                }
+            }
+
             // Render the homepage
             (
                 StatusCode::OK,