module Network.Wai.Middleware.MethodOverride (
methodOverride,
) where
import Control.Monad (join)
import Network.Wai (Middleware, queryString, requestMethod)
methodOverride :: Middleware
methodOverride :: Middleware
methodOverride Application
app Request
req =
Application
app Request
req'
where
req' :: Request
req' =
case (Request -> ByteString
requestMethod Request
req, 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
"_method" ([(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
(ByteString
"POST", Just ByteString
m) -> Request
req{requestMethod = m}
(ByteString, Maybe ByteString)
_ -> Request
req