New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Rack's own headers classes where appropriate. #47091
Use Rack's own headers classes where appropriate. #47091
Conversation
Rack 3 response headers must be a mutable hash with lower-case keys. Rack provides `Rack::Headers` as a compatibility layer for existing systems which don't conform to this requirement. Prefer `Rack::Utils::HeaderHash` on Rack 2, and `Rack::Headers` on Rack 3. Remove some of the response test cases which test `nil` header keys as these are considered invalid, and will fail with `Rack::Headers`.
4aecac8
to
0b4b4c6
Compare
@rafaelfranca this is also another relatively straight forward compatibility update with minimal changes to public interface. It actually corrects some cases because before using a hash, header keys were case sensitive, but using the headers class from Rack avoids this problem. |
Thanks so much for the quick turn around!!! |
if @response.sending? || @response.sent? | ||
raise ActionDispatch::IllegalStateError, "header already sent" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we still protecting against setting headers after the response has started sending?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To the extent that it's reasonable and possible, yes, however Rack 3 requires a mutable hash for the headers. We might need to revisit this and clarify the exact behaviour.
0b4b4c6#diff-1e126b979451002d618e43e3517230f7b925cc0af5e693bb525db18259df4b85R455
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, there were plenty of ways to bypass []=
in the previous implementation... so I'm a little concerned the previous implementation was insufficient. e.g. Hash#update
...
Rack 3 response headers must be a mutable hash with lower-case keys. Rack provides
Rack::Headers
as a compatibility layer for existing systems which don't conform to this requirement. PreferRack::Utils::HeaderHash
on Rack 2, andRack::Headers
on Rack 3.Remove some of the response test cases which test
nil
header keys as these are considered invalid, and will fail withRack::Headers
.