I am having a hard time trying to modify the Flask request object before routing occurs.
My API Module (not my entire Flask app) depends on faking PUT and DELETE operations by sending a special header. I need to check out the contents of the "-Method" header and modify the Flask Request object accordingly, before Flask does its routing.
This is the short, pythonic, explicit code I'd like to work:
@api.before_request
def method_scrubbing():
if request.headers.has_key('-Method'):
method = request.headers['-Method'].upper()
tagalog.log("in before_request, -Method = {}".format(method), 'force')
if method not in ['PUT', 'DELETE']:
raise ApiMethodException(method)
else:
request.method = method
...but I get a "read only property" error from werkzeug: http://drktd.com/74yk
I've seem Armin's post at http://flask.pocoo.org/snippets/38/ but this appears to be app-wide (not specific to a module).