| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Web.Apiary.Cookie
Description
Cookie support for Apiary.
{--}
{--}
{--} -- for implicit signature
{--} -- for explicit signature
import Web.Apiary
import Web.Apiary.Cookie
import Network.Wai.Handler.Warp
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.ByteString.Char8 as S
withCookie function give Cookie data type for encrypt cookie.
setCookie function set cookie. cookie value is automatically encrypted.
main :: IO () main =withCookiedef $ run 3000 . runApiary def $ do [capture|/:String|] . action $ \s -> dosetCookie(def { setCookieName = "param", setCookieValue = S.pack s })setCookie(def { setCookieName = "dog", setCookieValue = "bowwow" }) contentType "text/plain" lbs "lucky cookie." root $ action_ splittedAction
getCookie functions, get and auto decrypt cookie.
splittedAction :: (Monad m, HasCookie) => ActionT m ()
splittedAction = do
s <- getCookie' "param"
p <- getCookie' "dog"
contentType "text/plain"
lbs $ L.unlines [L.fromStrict s, L.fromStrict p]
- first, access localhost:3000, 404 page not found shown.
getCookie' function pass next handler when cookie key is not found,
and next handler is not exists. so 404.
- next, you access localhost:3000/hoge, set param=hoge, dog=bowwow to cookie.
- then access localhost:3000, show hoge<CR>bowwow.
- type HasCookie = ?webApiaryCookieCookie :: Cookie
- newtype CookieConfig = CookieConfig {}
- withCookie :: CookieConfig -> (HasCookie => IO b) -> IO b
- setCookie :: (MonadIO m, HasCookie) => SetCookie -> ActionT m ()
- getCookies :: (Monad m, HasCookie) => ActionT m (Maybe [(ByteString, Maybe ByteString)])
- getCookies' :: (Monad m, HasCookie) => ActionT m [(ByteString, Maybe ByteString)]
- getCookie :: (Monad m, HasCookie) => ByteString -> ActionT m (Maybe ByteString)
- getCookie' :: (Monad m, HasCookie) => ByteString -> ActionT m ByteString
- module Web.Cookie
- module Data.Default.Class
Documentation
withCookie :: CookieConfig -> (HasCookie => IO b) -> IO b Source
Give cookie encryption key.
setter
getter
getCookies :: (Monad m, HasCookie) => ActionT m (Maybe [(ByteString, Maybe ByteString)]) Source
get cookies. first Maybe indicate cookie header exists or not, second Maybe indicate decryption status.
getCookies' :: (Monad m, HasCookie) => ActionT m [(ByteString, Maybe ByteString)] Source
like getCookies, but when cookie header isn't exists, pass next handler.
getCookie :: (Monad m, HasCookie) => ByteString -> ActionT m (Maybe ByteString) Source
get cookie of specific key.
getCookie' :: (Monad m, HasCookie) => ByteString -> ActionT m ByteString Source
Reexport
SetCookie(..)
module Web.Cookie
def
module Data.Default.Class