salvia-0.0.4: src/Network/Salvia/Handlers/Cookie.hs
module Network.Salvia.Handlers.Cookie (
hSetCookies
, hGetCookies
, newCookie
) where
import Control.Applicative hiding (empty)
import Control.Monad.State
import Data.Time.Format
import Data.Time.LocalTime
import System.Locale (defaultTimeLocale)
import Network.Salvia.Httpd
import Network.Protocol.Cookie
import Network.Protocol.Http (getCookie, setCookie)
hSetCookies :: Cookies -> Handler ()
hSetCookies = modResponse . setCookie . showCookies
hGetCookies :: Handler (Maybe Cookies)
hGetCookies = parseCookies <$> getCookie <$> gets request
-- Convenient method for creating cookies that expire in the near future and
-- are bound to the domain and port this server runs on. The path will be
-- locked to root.
newCookie :: LocalTime -> Handler Cookie
newCookie expire = do
httpd <- gets config
return $ empty {
path = Just "/"
-- , domain = Just $ '.' : hostname httpd
, port = [fromEnum $ listenPort httpd]
, expires = Just $ formatTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S %Z" expire
}