Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cookie support for Apiary.
{--} {--} -- for reflection {--} 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 =withCookie
def $ 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
In splitted action, you must add sigunature
with Given
Cookie
ristriction.
getCookie
functions, get and auto decrypt cookie.
splittedAction :: (Monad m, Given Cookie) => 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.
- data Cookie
- newtype CookieConfig = CookieConfig {}
- withCookie :: CookieConfig -> (Given Cookie => IO b) -> IO b
- setCookie :: (MonadIO m, Given Cookie) => SetCookie -> ActionT m ()
- getCookies :: (Monad m, Given Cookie) => ActionT m (Maybe [(ByteString, Maybe ByteString)])
- getCookies' :: (Monad m, Given Cookie) => ActionT m [(ByteString, Maybe ByteString)]
- getCookie :: (Monad m, Given Cookie) => ByteString -> ActionT m (Maybe ByteString)
- getCookie' :: (Monad m, Given Cookie) => ByteString -> ActionT m ByteString
- def :: Default a => a
- data SetCookie :: *
- class Given a
Documentation
withCookie :: CookieConfig -> (Given Cookie => IO b) -> IO b Source
Give cookie encryption key.
setter
getter
getCookies :: (Monad m, Given Cookie) => 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, Given Cookie) => ActionT m [(ByteString, Maybe ByteString)] Source
like getCookies
, but when cookie header isn't exists, pass next handler.
getCookie :: (Monad m, Given Cookie) => ByteString -> ActionT m (Maybe ByteString) Source
get cookie of specific key.
getCookie' :: (Monad m, Given Cookie) => ByteString -> ActionT m ByteString Source