module Control.Monad.Apiary.Filter (
method, stdMethod
, Control.Monad.Apiary.Filter.httpVersion
, http09, http10, http11
, root
, capture
, query
, (=:), (=!:), (=?:), (?:), (=*:), (=+:)
, hasQuery
, hasHeader
, eqHeader
, headers
, header
, header'
, ssl
, module Network.HTTP.Types
, module Control.Monad.Apiary.Filter.Internal.Strategy
) where
import Control.Monad
import Network.Wai as Wai
import qualified Network.HTTP.Types as HT
import Network.HTTP.Types (StdMethod(..))
import qualified Data.ByteString as S
import Data.Proxy
import Data.Reflection
import Data.Apiary.SList
import Data.Apiary.Param
import Control.Monad.Apiary.Action.Internal
import Control.Monad.Apiary.Filter.Internal
import qualified Control.Monad.Apiary.Filter.Internal.Strategy as Strategy
import Control.Monad.Apiary.Filter.Internal.Strategy (pFirst, pOne, pOption, pCheck, pMany, pSome)
import Control.Monad.Apiary.Filter.Internal.Capture.TH
import Control.Monad.Apiary.Internal
method :: HT.Method -> Apiary c a -> Apiary c a
method m = function_ ((m ==) . requestMethod)
stdMethod :: StdMethod -> Apiary c a -> Apiary c a
stdMethod = method . HT.renderStdMethod
ssl :: Apiary c a -> Apiary c a
ssl = function_ isSecure
httpVersion :: HT.HttpVersion -> Apiary c b -> Apiary c b
httpVersion v = function_ $ (v ==) . Wai.httpVersion
http09 :: Apiary c b -> Apiary c b
http09 = Control.Monad.Apiary.Filter.httpVersion HT.http09
http10 :: Apiary c b -> Apiary c b
http10 = Control.Monad.Apiary.Filter.httpVersion HT.http10
http11 :: Apiary c b -> Apiary c b
http11 = Control.Monad.Apiary.Filter.httpVersion HT.http11
root :: Apiary c b -> Apiary c b
root m = do
rs <- rootPattern `liftM` apiaryConfig
function_ (\r -> rawPathInfo r `elem` rs) m
query :: (Query a, Strategy.Strategy w)
=> S.ByteString
-> Proxy (w a)
-> Apiary (Strategy.SNext w as a) b
-> Apiary as b
query k p = function $ \l r -> Strategy.readStrategy readQuery ((k ==) . fst) p (queryString r) l
(=:) :: Query a => S.ByteString -> Proxy a -> Apiary (Snoc as a) b -> Apiary as b
k =: t = query k (pFirst t)
(=!:) :: Query a => S.ByteString -> Proxy a -> Apiary (Snoc as a) b -> Apiary as b
k =!: t = query k (pOne t)
(=?:) :: Query a => S.ByteString -> Proxy a -> Apiary (Snoc as (Maybe a)) b -> Apiary as b
k =?: t = query k (pOption t)
(?:) :: Query a => S.ByteString -> Proxy a -> Apiary as b -> Apiary as b
k ?: t = query k (pCheck t)
(=*:) :: Query a => S.ByteString -> Proxy a -> Apiary (Snoc as [a]) b -> Apiary as b
k =*: t = query k (pMany t)
(=+:) :: Query a => S.ByteString -> Proxy a -> Apiary (Snoc as [a]) b -> Apiary as b
k =+: t = query k (pSome t)
hasQuery :: S.ByteString -> Apiary c a -> Apiary c a
hasQuery q = query q (Proxy :: Proxy (Strategy.Check ()))
hasHeader :: HT.HeaderName -> Apiary as b -> Apiary as b
hasHeader n = header' pCheck ((n ==) . fst)
eqHeader :: HT.HeaderName
-> S.ByteString
-> Apiary as b
-> Apiary as b
eqHeader k v = header' pCheck (\(k',v') -> k == k' && v == v')
header :: HT.HeaderName
-> Apiary (Snoc as S.ByteString) b -> Apiary as b
header n = header' pFirst ((n ==) . fst)
headers :: HT.HeaderName -> Apiary (Snoc as [S.ByteString]) b -> Apiary as b
headers n = header' limit100 ((n ==) . fst)
where
limit100 :: Proxy x -> Proxy (Strategy.LimitSome $(int 100) x)
limit100 _ = Proxy
header' :: (Strategy.Strategy w)
=> (forall x. Proxy x -> Proxy (w x))
-> (HT.Header -> Bool)
-> Apiary (Strategy.SNext w as S.ByteString) b
-> Apiary as b
header' pf kf = function $ \l r ->
Strategy.readStrategy Just kf (pf pByteString) (requestHeaders r) l