#32159: AsyncTestClient does not respect extra headers.
-------------------------------------+-------------------------------------
     Reporter:  Ryan Vinzent         |                    Owner:  Carlton
                                     |  Gibson
         Type:  Bug                  |                   Status:  assigned
    Component:  Testing framework    |                  Version:  3.1
     Severity:  Release blocker      |               Resolution:
     Keywords:  AsyncTestClient,     |             Triage Stage:  Accepted
  AsyncRequestFactory                |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

 So the PR adds corrects the `extra` handling to set the header, according
 to the ASGI spec, in `scope['headers']`, and `ASGIRequest` then populates
 `request.headers` and `request.META` as normal.

 The one difference, that I don't think is worth trying to make the same,
 is that you don't use the `HTTP_` prefix when passing the headers. So the
 example from the description would be:

 {{{
 client = AsyncTestClient()
 await client.get("/api/my-endpoint", AUTHORIZATION="Bearer faketoken")
 }}}

 I've updated the
 [https://docs.djangoproject.com/en/dev/topics/testing/tools/#testing-
 asynchronous-code Testing asynchronous code] docs (in the PR) to draw out
 this difference.

 > ...I don't think is worth trying to make the same...

 Due to the fact that the `HTTP_` into `request.META` mapping is inside
 `ASGIRequest` we'd need to map from `HTTP_` to lowercased format as
 expected in the ASGI `scope` to map back again in `ASGIRequest`. (Contrast
 this with `Client` which just provides the WSGI `environ`…) — It would be
 a lot of complexity, for a worse API, just to be consistent with a
 hangover from CGI...

 In that case, simply saying ''Don't use the `HTTP_` prefix with
 `AsyncClient'' seems a much cleaner approach.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32159#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.6f72a1cdd6cafeb15ed28d4e8aa559a2%40djangoproject.com.

Reply via email to