django / asgiref

ASGI specification and utilities
https://asgi.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1.46k stars 207 forks source link

Why `http.response.start` exists? #445

Closed Kludex closed 5 months ago

Kludex commented 5 months ago

I've been wondering... Uvicorn is the only ASGI server that sends http.response.start, and then processes the body. The problem with this approach, is that the successful response may be a lie, if there's an error when processing the body.

And... I was thinking about changing the behavior on Uvicorn.

I was wondering, why do we allow http.response.start to be sent before the body?

andrewgodwin commented 5 months ago

The idea was to emulate the WSGI behaviour, where you can begin the HTTP response before you then start streaming the body contents (start_response versus the contents of an iterator).