#1505·falcon

Ability to execute logic after the response is fully streamed

Author: vytas7Created May 5, 2019Updated Sep 14, 2026
Labelsenhancementproposalin progressinstrumentation

Right now, the middleware method process_response can be used to post-process responses after they are routed and handled by responders.

However, in case response body is a stream, one may want to execute logic when the stream iterable is exausted. We are already wrapping req.stream in some cases, so we could extend this to wrap .close() with code to execute the relevant method (finalize_response?) from middlewares added to the API.

Use cases could include cleaning up resources that were used to stream the response, such as releasing database connections back to the pool.