Closed jules-ch closed 3 months ago
Debugging the receive_wrapper is never called in Response.__call__
.
Just a guess there:
It may have other implication since the receive function is never called as part of the request response cycle.
Just tested and the uvicorn.protocols.http.httptools_impl:RequestResponseCycle.receive
for example is never called.
Adding await receive()
seems to do the trick.
If you never call request.body()
or similar indeed receive
will never be called. Why would you expect it to be called?
Oh my bad just found out receive is only used when you need to access to request body as you said. Just got confused there. For access to request and mutating request headers how would I do that ?
It just feels the event should still be sent as per the ASGI spec.
Looking at example in the doc with logging the request size. Since the event is never sent. Then logging of the request size is never triggered
That's how ASGI works. Happy to tweak wording or examples to make it more explicit.
In case you find it helpful I gave a talk last year that covers ASGI generally (although maybe not this specific case): https://youtu.be/fcfyDvK_A6Q?si=hwwenyLUr3xOujQh.
It seems receive calls cannot be wrapped when using Pure ASGI Middleware.
I followed the example stated in the docs but it just does not work, the wrapped function is never called.
Wrapped send work as expected.
See here in the docs : https://www.starlette.io/middleware/#inspecting-or-modifying-the-request
Expected Behaviour
wrapped received coroutine called
Minimal example