on master help sign in
MethodOverride: only on POST
bf766e3Michael Snoyman
wai-extra/Network/Wai/Middleware/MethodOverride.hs+7−3
@@ -8,11 +8,15 @@ import Control.Monad (join)
8
8
9-- | Allows overriding of the HTTP request method via the _method query string
9-- | Allows overriding of the HTTP request method via the _method query string
10-- parameter.
10-- parameter.
11+--
12+-- This middlware only applies when the initial request method is POST. This
13+-- allow submitting of normal HTML forms, without worries of semantics
14+-- mismatches in the HTTP spec.
11methodOverride :: Middleware
15methodOverride :: Middleware
12methodOverride app req =
16methodOverride app req =
13 app req'
17 app req'
14 where
18 where
15 req' =
19 req' =
16− case join $ lookup "_method" $ queryString req of
20+ case (requestMethod m, join $ lookup "_method" $ queryString req) of
17− Nothing -> req
18− Just m -> req { requestMethod = m }
21+ ("POST", Just m) -> req { requestMethod = m }
22+ _ -> req