Created
October 18, 2011 19:22
-
-
Save mattupstate/1296413 to your computer and use it in GitHub Desktop.
HTTP method override middleware for Werkzeug
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 HTTPMethodOverrideMiddleware(object): | |
def __init__(self, app): | |
self.app = app | |
def __call__(self, environ, start_response): | |
if 'METHOD_OVERRIDE' in environ.get('QUERY_STRING', ''): | |
args = url_decode(environ['QUERY_STRING']) | |
method = args.get('__METHOD_OVERRIDE__') | |
if method in ['GET', 'POST', 'PUT', 'DELETE']: | |
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