Add support for rack.response_finished (#3681)#9
Add support for rack.response_finished (#3681)#9MitchLewis930 wants to merge 1 commit intopr_059_beforefrom
rack.response_finished (#3681)#9Conversation
* 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>
Greptile OverviewGreptile SummaryThis PR implements support for Key changes:
Critical Issue Found: Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Server
participant App as Rack App
participant Callbacks as rack.response_finished
Client->>Server: HTTP Request
Server->>Server: Initialize env with rack.response_finished=[]
Server->>App: call(env)
App->>Callbacks: Register callback(s)
App-->>Server: [status, headers, body]
alt Success Path
Server->>Server: prepare_response(status, headers, body)
Server->>Client: Send HTTP Response
Server->>Callbacks: Execute callbacks(env, status, headers, nil)
else Error Path
App-->>Server: raise Exception
Server->>Server: Catch error, set status=500
Server->>Client: Send Error Response
Server->>Callbacks: Execute callbacks(env, 500, headers, error)
else Early Return (Hijack/Async)
Server->>Server: return :async
Server->>Callbacks: Execute callbacks(env, nil, nil, nil)
Note over Callbacks: ⚠️ BUG: status/headers undefined
end
|
| io_buffer = client.io_buffer | ||
| socket = client.io # io may be a MiniSSL::Socket | ||
| app_body = nil | ||
| error = nil |
There was a problem hiding this comment.
status and headers should be initialized here to prevent NameError when early returns happen (lines 57, 113, 122) before these variables are assigned
| error = nil | |
| error = nil | |
| status = nil | |
| headers = nil |
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/puma/request.rb
Line: 55:55
Comment:
`status` and `headers` should be initialized here to prevent `NameError` when early returns happen (lines 57, 113, 122) before these variables are assigned
```suggestion
error = nil
status = nil
headers = nil
```
How can I resolve this? If you propose a fix, please make it concise.
PR_059