Created
January 15, 2012 15:00
-
-
Save longfin/1616103 to your computer and use it in GitHub Desktop.
MethodRewriteMiddleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from werkzeug import url_decode | |
class MethodRewriteMiddleware(object): | |
""" | |
app = MethodRewriteMiddleware(app) | |
""" | |
def __init__(self, app, input_name = '__method__'): | |
self.app = app | |
self.input_name = input_name | |
def __call__(self, environ, start_response): | |
if self.input_name in environ.get('QUERY_STRING', ''): | |
args = url_decode(environ['QUERY_STRING']) | |
method = args.get(self.input_name) | |
if method: | |
method = method.encode('ascii', 'replace') | |
environ['REQUEST_METHOD'] = method | |
return self.app(environ, start_response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment