3 , GeneralizedNewtypeDeriving
9 module Network.HTTP.Lucu.Router
10 ( -- * The 'Router' arrow
14 -- * Testing for URI scheme
23 import Control.Applicative
24 import Control.Category
26 import Control.Arrow.ArrowKleisli
27 import Control.Arrow.List
28 import Control.Monad.IO.Class
29 import Data.Ascii (CIAscii)
31 import Network.URI hiding (scheme)
32 import Network.HTTP.Lucu.Utils
33 import Prelude.Unicode
38 unRouter ∷ ListTArrow m α β
50 runRouter ∷ (Applicative m, MonadIO m) ⇒ Router m α β → α → m (Maybe β)
51 {-# INLINE runRouter #-}
52 runRouter = ((listToMaybe <$>) ∘) ∘ runListTArrow ∘ unRouter
55 anyScheme ∷ Arrow (⇝) ⇒ URI ⇝ (Host, Path)
56 {-# INLINEABLE anyScheme #-}
57 anyScheme = arr uriHost &&& arr uriPathSegments
60 schemeWith ∷ (ArrowChoice (⇝), ArrowZero (⇝))
63 {-# INLINEABLE schemeWith #-}
66 if f (uriCIScheme uri) then
71 -- |@'scheme' s@ = @'schemeWith' ('==' s)@
72 scheme ∷ (ArrowChoice (⇝), ArrowZero (⇝)) ⇒ CIAscii → URI ⇝ (Host, Path)
74 scheme = schemeWith ∘ (≡)
76 -- |@'http' = 'scheme' \"http\" '<+>' 'scheme' \"https\"@
77 http ∷ (ArrowChoice (⇝), ArrowPlus (⇝), ArrowZero (⇝)) ⇒ URI ⇝ (Host, Path)
79 http = scheme "http" <+> scheme "https"
81 -- |@'http'' = 'scheme' \"http\"@
82 http' ∷ (ArrowChoice (⇝), ArrowZero (⇝)) ⇒ URI ⇝ (Host, Path)
85 -- |@'https' = 'scheme' \"https\"@
86 https ∷ (ArrowChoice (⇝), ArrowZero (⇝)) ⇒ URI ⇝ (Host, Path)
87 https = scheme "https"