Describe the bug
Putting the middleware on top of middleware list β as suggested by doc β doesn't allow next middlewares to potentially add/override HTTP headers through:
request.META['HTTP_CUSTOM_HEADER'] = "CUSTOM VALUE"
This is due to using django_guid.utils.get_id_from_header()
in django_guid.middleware.process_incoming_request()
, which triggers an earlier immutable HttpHeader
object build, so any add/override headers intent has no impact.
Would be better to use request.META
to get/set headers.
To Reproduce
Create a middleware
def foo_middleware(get_response):
def middleware(request):
request.META["HTTP_X_FOO"] = "foo"
return get_response(request)
return middleware
Add middleware after django_guid
MIDDLEWARE = [
"django_guid.middleware.guid_middleware",
"foo.foo_middleware",
]
Try to access the header in a view
@api_view(["GET"])
def test_view(request):
assert request.headers.get("X-Foo") == "foo"
Now retry by removing "django_guid.middleware.guid_middleware"
from MIDDLEWARE
.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too