notModified and setEtag
This commit is contained in:
parent
d1815857df
commit
b38abdba0f
@ -94,6 +94,7 @@ module Yesod.Core.Handler
|
||||
, sendWaiApplication
|
||||
, sendRawResponse
|
||||
, sendRawResponseNoConduit
|
||||
, notModified
|
||||
-- * Different representations
|
||||
-- $representations
|
||||
, selectRep
|
||||
@ -112,6 +113,7 @@ module Yesod.Core.Handler
|
||||
, neverExpires
|
||||
, alreadyExpired
|
||||
, expiresAt
|
||||
, setEtag
|
||||
-- * Session
|
||||
, SessionMap
|
||||
, lookupSession
|
||||
@ -590,6 +592,13 @@ sendRawResponse raw = control $ \runInIO ->
|
||||
yield bs
|
||||
src' src
|
||||
|
||||
-- | Send a 304 not modified response immediately. This is a short-circuiting
|
||||
-- action.
|
||||
--
|
||||
-- Since 1.4.4
|
||||
notModified :: MonadHandler m => m a
|
||||
notModified = sendWaiResponse $ W.responseBuilder H.status304 [] mempty
|
||||
|
||||
-- | Return a 404 not found page. Also denotes no handler available.
|
||||
notFound :: MonadHandler m => m a
|
||||
notFound = hcError NotFound
|
||||
@ -699,6 +708,18 @@ alreadyExpired = setHeader "Expires" "Thu, 01 Jan 1970 05:05:05 GMT"
|
||||
expiresAt :: MonadHandler m => UTCTime -> m ()
|
||||
expiresAt = setHeader "Expires" . formatRFC1123
|
||||
|
||||
-- | Check the if-none-match header and, if it matches the given value, return
|
||||
-- a 304 not modified response. Otherwise, set the etag header to the given
|
||||
-- value.
|
||||
--
|
||||
-- Since 1.4.4
|
||||
setEtag :: MonadHandler m => Text -> m ()
|
||||
setEtag etag = do
|
||||
mmatch <- lookupHeader "if-none-match"
|
||||
case mmatch of
|
||||
Just x | encodeUtf8 etag == x -> notModified
|
||||
_ -> addHeader "etag" etag
|
||||
|
||||
-- | Set a variable in the user's session.
|
||||
--
|
||||
-- The session is handled by the clientsession package: it sets an encrypted
|
||||
|
||||
@ -1 +1,3 @@
|
||||
__1.4.4__ Add the `notModified` and `setEtag` functions.
|
||||
|
||||
__1.4.3__ Switch to mwc-random for token generation.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod-core
|
||||
version: 1.4.3.1
|
||||
version: 1.4.4
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user