I want to implement a middleware in django, that will append a header on the request's existing headers, before the get_response(request) function.
Though, when trying like this:
request.headers['CUSTOM_HEADER'] = 'CUSTOM_VALUE'
I get an error: 'HttpHeaders' object does not support item assignment
Also in django's request (WSGIRequest), there is no add_headers function like the python's request module.
Any ideas on how this can be accomplished?
request
object itself, e.g.request.CUSTOM = 'CUSTOM_VALUE
. This is what several Django middlewares do. – Nonparticipating