setting Expires header in snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Set an Expires reponse header to this number of days from now. | |
expiresInDays :: Integer -> Snap () | |
expiresInDays n = do | |
now <- liftIO getCurrentTime | |
let later = addUTCTime (fromInteger $ n * 60 * 60 * 24) now | |
getResponse >>= return . addHeader "Expires" (formatRFC1123 later) >>= putResponse | |
formatRFC1123 :: UTCTime -> BS.ByteString | |
formatRFC1123 = BS8.pack . formatTime defaultTimeLocale "%a, %d %b %Y %X %Z" | |
Example: | |
route | |
[ ("public/images", expiresInDays 7 >> (serveDirectory $ cwd </> "public")) | |
, ("public", serveDirectory $ cwd </> "public") | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would suggest the more general
where expiresIn (operating in seconds, this has a proper Num instance also) and expiresInDays are expressed in terms of expiresOn.