about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frontend/mod.rs49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
index 69f6aa5..e142ee1 100644
--- a/src/frontend/mod.rs
+++ b/src/frontend/mod.rs
@@ -244,6 +244,11 @@ pub async fn homepage<D: Storage>(
     // This is stupid, but there is no other way.
     let hcard_url: url::Url = format!("https://{}/", host).parse().unwrap();
     let feed_path = format!("https://{}/feeds/main", host);
+    let mut headers = axum::http::HeaderMap::new();
+    headers.insert(
+        axum::http::header::CONTENT_TYPE,
+        axum::http::HeaderValue::from_static(r#"text/html; charset="utf-8""#),
+    );
 
     let user = session.as_deref().map(|s| &s.me);
     match tokio::try_join!(
@@ -265,13 +270,16 @@ 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,
+                    axum::http::HeaderValue::from_static("private")
+                );
+            }
             // Render the homepage
             (
                 StatusCode::OK,
-                [(
-                    axum::http::header::CONTENT_TYPE,
-                    r#"text/html; charset="utf-8""#,
-                )],
+                headers,
                 Template {
                     title: blogname.as_ref(),
                     blog_name: blogname.as_ref(),
@@ -286,7 +294,7 @@ pub async fn homepage<D: Storage>(
                     .to_string(),
                 }
                 .to_string(),
-            )
+            ).into_response()
         }
         Err(err) => {
             if err.code == StatusCode::NOT_FOUND {
@@ -296,7 +304,7 @@ pub async fn homepage<D: Storage>(
                     StatusCode::FOUND,
                     [(axum::http::header::LOCATION, "/.kittybox/onboarding")],
                     String::default(),
-                )
+                ).into_response()
             } else {
                 error!("Error while fetching h-card and/or h-feed: {}", err);
                 // Return the error
@@ -308,11 +316,7 @@ pub async fn homepage<D: Storage>(
                 );
 
                 (
-                    err.code(),
-                    [(
-                        axum::http::header::CONTENT_TYPE,
-                        r#"text/html; charset="utf-8""#,
-                    )],
+                    err.code(), headers,
                     Template {
                         title: blogname.as_ref(),
                         blog_name: blogname.as_ref(),
@@ -325,7 +329,7 @@ pub async fn homepage<D: Storage>(
                         .to_string(),
                     }
                     .to_string(),
-                )
+                ).into_response()
             }
         }
     }
@@ -354,13 +358,22 @@ pub async fn catchall<D: Storage>(
 
                 db.get_channels(&host).map(|i| i.unwrap_or_default())
             );
+            let mut headers = axum::http::HeaderMap::new();
+            headers.insert(
+                axum::http::header::CONTENT_TYPE,
+                axum::http::HeaderValue::from_static(r#"text/html; charset="utf-8""#),
+            );
+            if user.is_some() {
+                headers.insert(
+                    axum::http::header::CACHE_CONTROL,
+                    axum::http::HeaderValue::from_static("private")
+                );
+            }
+
             // Render the homepage
             (
                 StatusCode::OK,
-                [(
-                    axum::http::header::CONTENT_TYPE,
-                    r#"text/html; charset="utf-8""#,
-                )],
+                headers,
                 Template {
                     title: blogname.as_ref(),
                     blog_name: blogname.as_ref(),
@@ -376,7 +389,7 @@ pub async fn catchall<D: Storage>(
                     },
                 }
                 .to_string(),
-            )
+            ).into_response()
         }
         Err(err) => {
             let (blogname, channels) = tokio::join!(
@@ -403,7 +416,7 @@ pub async fn catchall<D: Storage>(
                     .to_string(),
                 }
                 .to_string(),
-            )
+            ).into_response()
         }
     }
 }