When looping a generator in StreamingResponse() using FastAPI/starlette
https://www.starlette.io/responses/#streamingresponse
how can we tell if the connection was somehow disconnected, so a event could be fired and handled somewhere else?
Scenario: writing an API with text/event-stream
, need to know when client closed the connection.
Consider using
request.is_disconnected()
. From Starlette's docs:Unfortunately, there seems to be no other documentation regarding this API. Have a look at the MR that introduced this feature: https://github.com/encode/starlette/pull/320