Skip to content

Commit

Permalink
Merge pull request #938 from fumieval/no-store
Browse files Browse the repository at this point in the history
wai-app-static: add NoStore to MaxAge
  • Loading branch information
snoyberg authored Sep 5, 2023
2 parents 7e89ac9 + e3e7a50 commit e185e20
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions wai-app-static/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
17 changes: 8 additions & 9 deletions wai-app-static/Network/Wai/Application/Static.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions wai-app-static/WaiAppStatic/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e185e20

Please sign in to comment.