diff options
Diffstat (limited to 'src/Cana/Router.hs')
-rw-r--r-- | src/Cana/Router.hs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/Cana/Router.hs b/src/Cana/Router.hs index 1454375..757e9c9 100644 --- a/src/Cana/Router.hs +++ b/src/Cana/Router.hs @@ -1,18 +1,42 @@ -- | -- Module : Cana.Router -module Cana.Router where +module Cana.Router + ( -- * Predicate combinators + (&&~) + , (||~) + -- * Predicates + , anyRoute + , geminiScheme + , routeHost + ) where import Cana.Types import Cana.Protocol import Cana.Monad +import Control.Arrow import Network.URI +infixr 3 &&~ +infixr 2 ||~ + +-- | A predicate that matches when both predicates match. +(&&~) :: Predicate -> Predicate -> Predicate +(&&~) a b = uncurry (&&) . (a &&& b) + +-- | A predicate that matches when one of the predicates matches. +(||~) :: Predicate -> Predicate -> Predicate +(||~) a b = uncurry (||) . (a &&& b) + -- | A predicate that always triggers, e.g. for catch-all routes. anyRoute :: Predicate anyRoute = const True +-- | A predicate that matches the @gemini://@ scheme. +geminiScheme :: Predicate +geminiScheme = (== "gemini:") . uriScheme . requestUri + -- | A predicate that matches the given hostname. routeHost :: String -> Predicate routeHost host request = case uriAuthority (requestUri request) of |