module Network.Wai.Middleware.Routed
( routedMiddleware
, hostedMiddleware
) where
import Network.Wai
import Data.ByteString (ByteString)
import Data.Text (Text)
routedMiddleware :: ([Text] -> Bool)
-> Middleware
-> Middleware
routedMiddleware :: ([Text] -> Bool) -> Middleware -> Middleware
routedMiddleware pathCheck :: [Text] -> Bool
pathCheck middle :: Middleware
middle app :: Application
app req :: Request
req
| [Text] -> Bool
pathCheck (Request -> [Text]
pathInfo Request
req) = Middleware
middle Application
app Request
req
| Bool
otherwise = Application
app Request
req
hostedMiddleware :: ByteString
-> Middleware
-> Middleware
hostedMiddleware :: ByteString -> Middleware -> Middleware
hostedMiddleware domain :: ByteString
domain middle :: Middleware
middle app :: Application
app req :: Request
req
| ByteString -> Request -> Bool
hasDomain ByteString
domain Request
req = Middleware
middle Application
app Request
req
| Bool
otherwise = Application
app Request
req
hasDomain :: ByteString -> Request -> Bool
hasDomain :: ByteString -> Request -> Bool
hasDomain domain :: ByteString
domain req :: Request
req = Bool -> (ByteString -> Bool) -> Maybe ByteString -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
domain) Maybe ByteString
mHost
where mHost :: Maybe ByteString
mHost = Request -> Maybe ByteString
requestHeaderHost Request
req