Skip to content

Instantly share code, notes, and snippets.

@longfin
Created January 15, 2012 15:00
Show Gist options
  • Save longfin/1616103 to your computer and use it in GitHub Desktop.
Save longfin/1616103 to your computer and use it in GitHub Desktop.
MethodRewriteMiddleware
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