Skip to content

Instantly share code, notes, and snippets.

@simonmichael simonmichael/gist:6050387
Last active Dec 20, 2015

Embed
What would you like to do?
setting Expires header in snap
-- | 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")
...
@gregorycollins

This comment has been minimized.

Copy link

gregorycollins commented Jul 22, 2013

I would suggest the more general

expiresOn :: UTCTime -> Snap ()
expiresIn :: NominalDiffTime -> Snap ()
expiresInDays :: Int -> Snap ()

where expiresIn (operating in seconds, this has a proper Num instance also) and expiresInDays are expressed in terms of expiresOn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.