-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG] Can't add/override HTTP headers in other middlewares #101
Comments
Unfortunately not @JonasKs. def get_id_from_header(request: 'HttpRequest') -> str:
# ...
header: str = request.headers.get(settings.guid_header_name) should theoretically become something like def get_id_from_header(request: 'HttpRequest') -> str:
# ...
header: str = request.META.get(settings.guid_header_name) to avoid next middlewares potentially break. |
Would you mind linking me docs for this? I don't use Django anymore, and I can't remember this behavior. |
Anyway, I'm very happy to accept a fix with a test for this if you'd like to contribute. I will probably, unfortunately not be able to review for at least a week. |
Django describes Overriding request headers in a middleware seems odd. That's why they are immutable. |
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:
This is due to using
django_guid.utils.get_id_from_header()
indjango_guid.middleware.process_incoming_request()
, which triggers an earlier immutableHttpHeader
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
Add middleware after django_guid
Try to access the header in a view
Now retry by removing
"django_guid.middleware.guid_middleware"
fromMIDDLEWARE
.The text was updated successfully, but these errors were encountered: