From 3cad3b211958a116e50bba82b154dd06ea916541 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 4 Jan 2024 17:44:36 +0100 Subject: [PATCH] Dont overwrite cache-control header in session middleware (#4337) --- crates/utils/translations | 2 +- src/session_middleware.rs | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/utils/translations b/crates/utils/translations index 15815aea7..a36865ee8 160000 --- a/crates/utils/translations +++ b/crates/utils/translations @@ -1 +1 @@ -Subproject commit 15815aea74fe97360afc03496b3ad62588649af0 +Subproject commit a36865ee8ca3658fea31ba948b67b75a812e84fc diff --git a/src/session_middleware.rs b/src/session_middleware.rs index d81251453..ab7eb3d62 100644 --- a/src/session_middleware.rs +++ b/src/session_middleware.rs @@ -85,16 +85,19 @@ where let mut res = svc.call(req).await?; - // Add cache-control header. If user is authenticated, mark as private. Otherwise cache - // up to one minute. - let cache_value = if jwt.is_some() { - "private" - } else { - "public, max-age=60" - }; - res - .headers_mut() - .insert(CACHE_CONTROL, HeaderValue::from_static(cache_value)); + // Add cache-control header if none is present + if !res.headers().contains_key(CACHE_CONTROL) { + // If user is authenticated, mark as private. Otherwise cache + // up to one minute. + let cache_value = if jwt.is_some() { + "private" + } else { + "public, max-age=60" + }; + res + .headers_mut() + .insert(CACHE_CONTROL, HeaderValue::from_static(cache_value)); + } Ok(res) }) }