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 pathCheck middle app req
| pathCheck (pathInfo req) = middle app req
| otherwise = app req
hostedMiddleware :: ByteString
-> Middleware
-> Middleware
hostedMiddleware domain middle app req
| hasDomain domain req = middle app req
| otherwise = app req
hasDomain :: ByteString -> Request -> Bool
hasDomain domain req = maybe False (== domain) mHost
where mHost = requestHeaderHost req