This caused a problem for me when I wrote code that passed when deployed,
but then the tests failed because the header wasn't getting into
request.headers like it did when the project was deployed.
I'm attaching a django tests patch that shows the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/31810>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "request_headers.diff" added.
test showing the issue
* status: new => closed
* resolution: => invalid
* component: Testing framework => HTTP handling
Comment:
You're trying to pass a custom header without HTTP prefix but
`HttpRequest.headers` contains only HTTP-prefixed headers, see
[https://docs.djangoproject.com/en/stable/ref/request-
response/#django.http.HttpRequest.headers documentation]. It's by design.
This has nothing to do with test `Client`. For example:
{{{
self.client.get('/request_headers/', HTTP_someheader='some header value')
}}}
works.
--
Ticket URL: <https://code.djangoproject.com/ticket/31810#comment:1>
Comment (by bcail):
Thanks felixxm. Did this change since django 2.2? On django 2.2, when I
pass a custom header in the request, it does show up in request.headers,
even though I'm not putting an HTTP_ prefix on the header. Is it showing
up in request.headers because django is adding HTTP_ to the custom header?
I do see that django added HTTP_ to the header in request.META, but in
request.headers it shows without the HTTP_.
It feels like if django is adding HTTP_ to the header, then the test
client should also add HTTP_ to the header?
--
Ticket URL: <https://code.djangoproject.com/ticket/31810#comment:2>