Skip to content

Comments

Add support for rack.response_finished (#3681)#9

Open
MitchLewis930 wants to merge 1 commit intopr_059_beforefrom
pr_059_after
Open

Add support for rack.response_finished (#3681)#9
MitchLewis930 wants to merge 1 commit intopr_059_beforefrom
pr_059_after

Conversation

@MitchLewis930
Copy link

@MitchLewis930 MitchLewis930 commented Jan 30, 2026

PR_059


Note

Medium Risk
Touches the core request lifecycle by adding new ensure-time callbacks and propagating status/headers/error, which could affect edge cases (async/hijack/shutdown) if assumptions about variable initialization or ordering are wrong.

Overview
Adds a new Rack env extension, rack.response_finished, surfaced via Puma::Const::RACK_RESPONSE_FINISHED and initialized in the binder/request env.

handle_request now captures any exception raised by the Rack app and, in an ensure block, invokes rack.response_finished callbacks in reverse order with (env, status, headers, error), swallowing/logging callback errors.

Tests are updated to run with a null log writer and to assert callback ordering and that the hook fires both on normal responses and when the app raises (receiving the 500 status and the original exception).

Written by Cursor Bugbot for commit 1b08ed7. This will update automatically on new commits. Configure here.

* Add support for `rack.response_finished`

It is very similar to `rack.after_reply`, but is part of the Rack spec.

It can't just be an alias because the spec state it has to
invoke callbacks in reverse order.

Fix: puma#3631
Ref: rack/rack#1777
Ref: rack/rack#1802

Co-Authored-By: Robert Laurin <robert.laurin@shopify.com>

* request.rb - more rename `e` to `error` changes

---------

Co-authored-by: Robert Laurin <robert.laurin@shopify.com>
Co-authored-by: MSP-Greg <Greg.mpls@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants