setUltDestReferer

This commit is contained in:
Michael Snoyman 2011-06-10 09:09:07 +03:00
parent da0e99c895
commit bd67a840ef
2 changed files with 20 additions and 1 deletions

View File

@ -79,7 +79,9 @@ module Yesod.Handler
-- ** Ultimate destination -- ** Ultimate destination
, setUltDest , setUltDest
, setUltDestString , setUltDestString
, setUltDestText
, setUltDest' , setUltDest'
, setUltDestReferer
, redirectUltDest , redirectUltDest
, clearUltDest , clearUltDest
-- ** Messages -- ** Messages
@ -466,8 +468,12 @@ setUltDest dest = do
setUltDestString $ render dest setUltDestString $ render dest
-- | Same as 'setUltDest', but use the given string. -- | Same as 'setUltDest', but use the given string.
setUltDestText :: Monad mo => Text -> GGHandler sub master mo ()
setUltDestText = setSession ultDestKey
setUltDestString :: Monad mo => Text -> GGHandler sub master mo () setUltDestString :: Monad mo => Text -> GGHandler sub master mo ()
setUltDestString = setSession ultDestKey setUltDestString = setSession ultDestKey
{-# DEPRECATED setUltDestString "Use setUltDestText instead" #-}
-- | Same as 'setUltDest', but uses the current page. -- | Same as 'setUltDest', but uses the current page.
-- --
@ -484,6 +490,19 @@ setUltDest' = do
render <- getUrlRenderParams render <- getUrlRenderParams
setUltDestString $ render (tm r) gets' setUltDestString $ render (tm r) gets'
-- | Sets the ultimate destination to the referer request header, if present.
--
-- This function will not overwrite an existing ultdest.
setUltDestReferer :: Monad mo => GGHandler sub master mo ()
setUltDestReferer = do
mdest <- lookupSession ultDestKey
maybe
(waiRequest >>= maybe (return ()) setUltDestBS . lookup "referer" . W.requestHeaders)
(const $ return ())
mdest
where
setUltDestBS = setUltDestText . T.pack . S8.unpack
-- | Redirect to the ultimate destination in the user's session. Clear the -- | Redirect to the ultimate destination in the user's session. Clear the
-- value from the session. -- value from the session.
-- --

View File

@ -1,5 +1,5 @@
name: yesod-core name: yesod-core
version: 0.8.2 version: 0.8.3
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>