Skip to content

Instantly share code, notes, and snippets.

@mattupstate
Created October 18, 2011 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattupstate/1296413 to your computer and use it in GitHub Desktop.
Save mattupstate/1296413 to your computer and use it in GitHub Desktop.
HTTP method override middleware for Werkzeug
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