module Network.Wai.Middleware.AcceptOverride
(
acceptOverride
) where
import Network.Wai
import Control.Monad (join)
import Network.Wai.Header (replaceHeader)
acceptOverride :: Middleware
acceptOverride :: Middleware
acceptOverride Application
app Request
req =
Application
app Request
req'
where
req' :: Request
req' =
case forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"_accept" forall a b. (a -> b) -> a -> b
$ Request -> Query
queryString Request
req of
Maybe ByteString
Nothing -> Request
req
Just ByteString
a -> Request
req {
requestHeaders :: RequestHeaders
requestHeaders = HeaderName -> ByteString -> RequestHeaders -> RequestHeaders
replaceHeader HeaderName
"Accept" ByteString
a forall a b. (a -> b) -> a -> b
$ Request -> RequestHeaders
requestHeaders Request
req
}