diff --git a/yesod-core/Yesod/Core.hs b/yesod-core/Yesod/Core.hs index 4362cee1..27f9c8be 100644 --- a/yesod-core/Yesod/Core.hs +++ b/yesod-core/Yesod/Core.hs @@ -33,6 +33,8 @@ module Yesod.Core , clientSessionBackend , saveClientSession , loadClientSession + , Header(..) + , BackendSession -- * JS loaders , loadJsYepnope , ScriptLoadPosition (..) @@ -50,6 +52,7 @@ module Yesod.Core ) where import Yesod.Internal.Core +import Yesod.Internal (Header(..)) import Yesod.Content import Yesod.Dispatch import Yesod.Handler diff --git a/yesod-core/Yesod/Internal/Core.hs b/yesod-core/Yesod/Internal/Core.hs index 0726cca2..6482e137 100644 --- a/yesod-core/Yesod/Internal/Core.hs +++ b/yesod-core/Yesod/Internal/Core.hs @@ -31,6 +31,7 @@ module Yesod.Internal.Core , clientSessionBackend , saveClientSession , loadClientSession + , BackendSession -- * jsLoader , ScriptLoadPosition (..) , BottomOfHeadAsync @@ -323,20 +324,6 @@ $doctype 5 key <- CS.getKey CS.defaultKeyFile return $ Just $ clientSessionBackend key 120 -type Session = [(Text, S8.ByteString)] - -data SessionBackend master = SessionBackend - { sbSaveSession :: master - -> W.Request - -> UTCTime -- ^ The current time - -> Session -- ^ The old session (before running handler) - -> Session -- ^ The final session - -> IO [Header] - , sbLoadSession :: master - -> W.Request - -> UTCTime -- ^ The current time - -> IO Session - } messageLoggerHandler :: Yesod m => Loc -> LogLevel -> Text -> GHandler s m () @@ -724,7 +711,7 @@ loadClientSession :: Yesod master -> master -> W.Request -> UTCTime - -> IO Session + -> IO BackendSession loadClientSession key _ req now = return . fromMaybe [] $ do raw <- lookup "Cookie" $ W.requestHeaders req val <- lookup sessionName $ parseCookies raw @@ -737,12 +724,12 @@ saveClientSession :: Yesod master -> master -> W.Request -> UTCTime - -> Session - -> Session + -> BackendSession + -> BackendSession -> IO [Header] saveClientSession key timeout master _ now _ sess = do -- fixme should we be caching this? - iv <- liftIO $ CS.randomIV + iv <- liftIO CS.randomIV return [AddCookie def { setCookieName = sessionName , setCookieValue = sessionVal iv diff --git a/yesod-core/Yesod/Internal/Session.hs b/yesod-core/Yesod/Internal/Session.hs index 320f7b86..ac84a862 100644 --- a/yesod-core/Yesod/Internal/Session.hs +++ b/yesod-core/Yesod/Internal/Session.hs @@ -1,8 +1,11 @@ module Yesod.Internal.Session ( encodeClientSession , decodeClientSession + , BackendSession + , SessionBackend(..) ) where +import Yesod.Internal (Header(..)) import qualified Web.ClientSession as CS import Data.Serialize import Data.Time @@ -12,6 +15,24 @@ import Data.Text (Text, pack, unpack) import Control.Arrow (first) import Control.Applicative ((<$>)) +import qualified Data.ByteString.Char8 as S8 +import qualified Network.Wai as W + +type BackendSession = [(Text, S8.ByteString)] + +data SessionBackend master = SessionBackend + { sbSaveSession :: master + -> W.Request + -> UTCTime -- ^ The current time + -> BackendSession -- ^ The old session (before running handler) + -> BackendSession -- ^ The final session + -> IO [Header] + , sbLoadSession :: master + -> W.Request + -> UTCTime -- ^ The current time + -> IO BackendSession + } + encodeClientSession :: CS.Key -> CS.IV -> UTCTime -- ^ expire time diff --git a/yesod-core/test/YesodCoreTest/WaiSubsite.hs b/yesod-core/test/YesodCoreTest/WaiSubsite.hs index baf66979..ee313c32 100644 --- a/yesod-core/test/YesodCoreTest/WaiSubsite.hs +++ b/yesod-core/test/YesodCoreTest/WaiSubsite.hs @@ -4,7 +4,6 @@ module YesodCoreTest.WaiSubsite (specs, Widget) where import YesodCoreTest.YesodTest import Yesod.Core import qualified Network.HTTP.Types as H -import Network.Wai myApp :: Application myApp _ = return $ responseLBS H.status200 [("Content-type", "text/plain")] "WAI"