apiary-cookie 0.4.3.3 → 0.5.1.0
raw patch · 3 files changed
+42/−2 lines, 3 filesdep +taggeddep +waidep ~apiaryPVP ok
version bump matches the API change (PVP)
Dependencies added: tagged, wai
Dependency ranges changed: apiary
API changes (from Hackage documentation)
+ Web.Apiary.Cookie: cookie :: (Strategy w, Query a, HasCookie, Monad m) => ByteString -> Proxy (w a) -> ApiaryT (SNext w as a) m b -> ApiaryT as m b
Files
- apiary-cookie.cabal +4/−2
- src/Web/Apiary/Cookie.hs +2/−0
- src/Web/Apiary/Cookie/Internal.hs +36/−0
apiary-cookie.cabal view
@@ -1,5 +1,5 @@ name: apiary-cookie-version: 0.4.3.3+version: 0.5.1.0 x-revision: 1 synopsis: Cookie support for apiary web framework. description:@@ -25,11 +25,13 @@ , mtl >=2.1 && <2.3 , transformers >=0.3 && <0.5 , bytestring >=0.10 && <0.11- , apiary >=0.4 && <0.6+ , apiary >=0.5.1 && <0.6 , cookie >=0.4 && <0.5 , clientsession >=0.9 && <0.10 , blaze-builder >=0.3 && <0.4 , data-default-class >=0.0 && <0.1+ , wai >=2.1 && <2.2+ , tagged >=0.7 && <0.8 hs-source-dirs: src ghc-options: -O2 -Wall
src/Web/Apiary/Cookie.hs view
@@ -59,6 +59,8 @@ , withCookie -- * setter , setCookie+ -- * filter+ , cookie -- * getter , getCookies, getCookies' , getCookie, getCookie'
src/Web/Apiary/Cookie/Internal.hs view
@@ -13,10 +13,16 @@ import Control.Monad.Trans import Control.Monad.Trans.Maybe +import Network.Wai import Web.Apiary import Web.ClientSession import Web.Cookie+import Data.Maybe+import Data.Proxy +import Control.Monad.Apiary.Filter.Internal+import Control.Monad.Apiary.Filter.Internal.Query+ import Blaze.ByteString.Builder import qualified Data.ByteString as S @@ -32,6 +38,35 @@ type HasCookie = ?webApiaryCookieCookie :: Cookie +cond :: (a -> Bool) -> (a -> b) -> (a -> b) -> a -> b+cond p t f a = if p a then t a else f a++-- | cookie filter. since 0.5.1.0.+--+-- can use like 'query' function.+--+-- example:+--+-- @+-- cookie "foo" pFirst pInt -- get first Int parameter from foo.+-- cookie "bar" pOption pDouble -- get first Double parameter from bar, allows no cookie.+-- cookie "baz" pMany (pMaybe pString) -- get zero or more baz cookies. allows cookie decrypt failure.+-- @+cookie :: (Strategy w, Query a, HasCookie, Monad m)+ => S.ByteString+ -> Proxy (w a)+ -> ApiaryT (SNext w as a) m b+ -> ApiaryT as m b+cookie k p = function $ \l r -> readStrategy k p (cookie' r) l++cookie' :: HasCookie => Request -> [(S.ByteString, Maybe S.ByteString)]+cookie' = + map (\(k,b) -> (k, decrypt (key ?webApiaryCookieCookie) b)) .+ concatMap parseCookies .+ take 100 . -- avoid hashdos+ mapMaybe (cond (("cookie" ==) . fst) (Just . snd) (const Nothing)) .+ requestHeaders+ -- | Give cookie encryption key. withCookie :: CookieConfig -> (HasCookie => IO b) -> IO b withCookie conf f = do@@ -44,6 +79,7 @@ let s = toByteString . renderSetCookie $ sc { setCookieValue = v' } addHeader "set-cookie" s +{-# DEPRECATED getCookies, getCookies', getCookie, getCookie' "use cookie filter" #-} -- | get cookies. first Maybe indicate cookie header exists or not, -- second Maybe indicate decryption status. getCookies :: (Monad m, HasCookie) => ActionT m (Maybe [(S.ByteString, Maybe S.ByteString)])