From 6654fa5e5c3658ae3f8203dcc5ac2f080a089643 Mon Sep 17 00:00:00 2001 From: Luke Frisken Date: Mon, 4 Dec 2023 05:45:45 +0400 Subject: [PATCH] Set Max-Age on cookies to persist across sessions --- src/disclaimer.rs | 6 ++++-- src/i18n.rs | 8 ++++++-- src/main.rs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/disclaimer.rs b/src/disclaimer.rs index e3f8bbb..368fb0c 100644 --- a/src/disclaimer.rs +++ b/src/disclaimer.rs @@ -6,7 +6,6 @@ use crate::{ templates::{render, TemplatesWithContext}, }; use axum::{ - body::Body, middleware::Next, response::{IntoResponse, Redirect, Response}, }; @@ -21,6 +20,9 @@ const DISCLAIMER_COOKIE_NAME: &str = "disclaimer"; /// accepted the pevious version. const DISCLAIMER_VERSION: u32 = 1; +/// The Max-Age property for the cookie (in seconds). +const DISCLAIMER_COOKIE_MAX_AGE_SECONDS: u64 = 365 * 24 * 60 * 60; + /// Handler to accept the disclaimer by setting a cookie [`DISCLAIMER_COOKIE_NAME`]. pub async fn handler(headers: HeaderMap) -> axum::response::Result { let referer_str = headers @@ -32,7 +34,7 @@ pub async fn handler(headers: HeaderMap) -> axum::response::Result eyre::Result<()> { .route("/", get(index::handler)) .route("/forecasts/:file_name", get(forecasts::handler)) .nest("/observations", observations::router()) - .layer(middleware::from_fn(disclaimer::middleware)) + .layer(middleware::from_fn(disclaimer::middleware)), ) .nest("/diagrams", diagrams::router()) .nest("/forecast-areas", forecast_areas::router())