Skip to content
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

Merged
merged 1 commit into from Jan 25, 2023

Conversation

ioquatix
Copy link
Contributor

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.

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`.
@ioquatix
Copy link
Contributor Author

@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.

@rafaelfranca rafaelfranca merged commit 2cf8740 into rails:main Jan 25, 2023
@ioquatix ioquatix deleted the rack-3-case-insensitive-headers branch January 25, 2023 22:25
@ioquatix
Copy link
Contributor Author

Thanks so much for the quick turn around!!!

Comment on lines -42 to -44
if @response.sending? || @response.sent?
raise ActionDispatch::IllegalStateError, "header already sent"
end
Copy link
Member

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?

Copy link
Contributor Author

@ioquatix ioquatix Jan 25, 2023

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

Copy link
Contributor Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants