I am writing middleware that, when it receives a request containing a header 'Foo', modifies its value, before passing the request on.
Django makes direct assignment illegal, so these do not work:
request.headers['Foo'] = 'bar'
request['Foo'] = 'bar'
I do have a working solution, but it's a bit hacky:
request.headers.__dict__['_store']['foo']=('Foo','bar')
Is there a cleaner way of doing it that I've missed?
new_request = request.headers.copy(), and then modify the new request params.request.headersis a better way to access the headers that are contained inrequest.META. But it's read-only. So in fact, just modifyrequest.META['HTTP_FOO'].