falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.53k stars 945 forks source link

Throw an exception into req.stream's generator upon disconnect? #2016

Open vytas7 opened 2 years ago

vytas7 commented 2 years ago

When req.stream is set to a generator, but the client disconnects prior to exhausting iteration, we could communicate this by throwing a specialized exception via .throw() or .athrow (async), respectively. Also decide whether this a good idea™ at all.

For WSGI, this would probably require wrapping the generator, and checking whether the generator was exhausted prior to calling its .close() method by the WSGI server. For ASGI, this would require implementing a mechanism to detect disconnect events while streaming, for instance, as proposed in #2015.

This is a breaking change if enabled by default; but it could also be made configurable by resp_options.