~ubuntu-branches/ubuntu/raring/haskell-wai-extra/raring-proposed

« back to all changes in this revision

Viewing changes to Network/Wai/Middleware/MethodOverride.hs

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-15 00:58:38 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120515005838-zicbz35rrqbn305y
Tags: 1.2.0.4-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import Network.Wai
7
7
import Control.Monad (join)
8
8
 
 
9
-- | Allows overriding of the HTTP request method via the _method query string
 
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.
9
15
methodOverride :: Middleware
10
16
methodOverride app req =
11
17
    app req'
12
18
  where
13
19
    req' =
14
 
        case join $ lookup "_method" $ queryString req of
15
 
            Nothing -> req
16
 
            Just m -> req { requestMethod = m }
 
20
        case (requestMethod req, join $ lookup "_method" $ queryString req) of
 
21
            ("POST", Just m) -> req { requestMethod = m }
 
22
            _ -> req