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