Skip to content

Commit

Permalink
MethodOverride: only on POST
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 16, 2012
1 parent e9399fc commit bf766e3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wai-extra/Network/Wai/Middleware/MethodOverride.hs
Expand Up @@ -8,11 +8,15 @@ import Control.Monad (join)

-- | Allows overriding of the HTTP request method via the _method query string
-- parameter.
--
-- This middlware only applies when the initial request method is POST. This
-- allow submitting of normal HTML forms, without worries of semantics
-- mismatches in the HTTP spec.
methodOverride :: Middleware
methodOverride app req =
app req'
where
req' =
case join $ lookup "_method" $ queryString req of
Nothing -> req
Just m -> req { requestMethod = m }
case (requestMethod m, join $ lookup "_method" $ queryString req) of
("POST", Just m) -> req { requestMethod = m }
_ -> req

0 comments on commit bf766e3

Please sign in to comment.