From e3e7a5085d94151d6c34419fe665d2746e850ffe Mon Sep 17 00:00:00 2001 From: Fumiaki Kinoshita Date: Fri, 25 Aug 2023 14:34:36 +0900 Subject: [PATCH] wai-app-static: add NoStore to MaxAge --- wai-app-static/ChangeLog.md | 4 ++++ .../Network/Wai/Application/Static.hs | 17 ++++++++--------- wai-app-static/WaiAppStatic/Types.hs | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/wai-app-static/ChangeLog.md b/wai-app-static/ChangeLog.md index ffdb5c7aa..1f5cd880c 100644 --- a/wai-app-static/ChangeLog.md +++ b/wai-app-static/ChangeLog.md @@ -1,5 +1,9 @@ # wai-app-static changelog +## 3.1.7.6 + +* Added `NoStore` constructor to `MaxAge` [#938](https://github.com/yesodweb/wai/pull/938) + ## 3.1.7.5 * Removed dependency of `time`, `old-locale` and `network` [#902](https://github.com/yesodweb/wai/pull/902) diff --git a/wai-app-static/Network/Wai/Application/Static.hs b/wai-app-static/Network/Wai/Application/Static.hs index 5f7060677..d8feb3253 100644 --- a/wai-app-static/Network/Wai/Application/Static.hs +++ b/wai-app-static/Network/Wai/Application/Static.hs @@ -205,23 +205,22 @@ cacheControl :: MaxAge -> (H.ResponseHeaders -> H.ResponseHeaders) cacheControl maxage = headerCacheControl . headerExpires where - ccInt = - case maxage of - NoMaxAge -> Nothing - MaxAgeSeconds i -> Just i - MaxAgeForever -> Just oneYear oneYear :: Int oneYear = 60 * 60 * 24 * 365 - headerCacheControl = - case ccInt of - Nothing -> id - Just i -> (:) ("Cache-Control", S8.append "public, max-age=" $ S8.pack $ show i) + maxAgeValue i = S8.append "public, max-age=" $ S8.pack $ show i + + headerCacheControl = case maxage of + NoMaxAge -> id + MaxAgeSeconds i -> (:) ("Cache-Control", maxAgeValue i) + MaxAgeForever -> (:) ("Cache-Control", maxAgeValue oneYear) + NoStore -> (:) ("Cache-Control", "no-store") headerExpires = case maxage of NoMaxAge -> id MaxAgeSeconds _ -> id -- FIXME MaxAgeForever -> (:) ("Expires", "Thu, 31 Dec 2037 23:55:55 GMT") + NoStore -> id -- | Turn a @StaticSettings@ into a WAI application. staticApp :: StaticSettings -> W.Application diff --git a/wai-app-static/WaiAppStatic/Types.hs b/wai-app-static/WaiAppStatic/Types.hs index db504a4c1..ab7d5c40d 100644 --- a/wai-app-static/WaiAppStatic/Types.hs +++ b/wai-app-static/WaiAppStatic/Types.hs @@ -67,6 +67,7 @@ type Pieces = [Piece] data MaxAge = NoMaxAge -- ^ no cache-control set | MaxAgeSeconds Int -- ^ set to the given number of seconds | MaxAgeForever -- ^ essentially infinite caching; in reality, probably one year + | NoStore -- ^ set cache-control to no-store @since 3.1.7.6 -- | Just the name of a folder. type FolderName = Piece