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 Constants #2435

Merged
merged 3 commits into from
May 4, 2024
Merged

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented May 4, 2024

Motivation

Since we dropped support for rack 1.X, we can replace some of our constants by Rack's constants. For instance, we had defined all supported http methods like Grape::Http::Headers::GET, Grape::Http::Headers::POST etc... but its already defined as Rack::GET, Rack::POST, etc... in Rack.

We also had redefined some Rack's constants in our code base like Grape::Env::RACK_INPUT, Grape::Env::RACK_REQUEST_FORM_HASH etc ... but these are Rack's internals and we should not rely on them and use Rack's constants Rack::INPUT, Rack::REQUEST_FORM_HASH.

At least, if Rack as major internal changes, Grape's will be in line with these changes even if it's a renaming or a drop. In the end, Grape is rack based and it all makes sense to do that since we were already using several Rack's utility functions.

Although, Grape should have a smaller memory footprint since we have less string literals.

Finally, I've changed Rack 3.0's integrations tests to make sure all our response headers are lowercased instead of looking if our internal headers are in lowercase. If makes more sense with #2425.

Thanks

Use Grape and Rack header constant in specs
Drop self.lowercase? and rack2 integration since we're using Grape::Util::Header
Change rack_3_0' integration tests to make sure we are returning lowercase headers
@ericproulx ericproulx requested a review from dblock May 4, 2024 16:50
Add CHANGELOG entry
@ericproulx ericproulx changed the title Use Rack constants instead of redefining it Use Rack constants May 4, 2024
@ericproulx ericproulx changed the title Use Rack constants Use Rack' constants May 4, 2024
@ericproulx ericproulx changed the title Use Rack' constants Use Rack constants May 4, 2024
@ericproulx ericproulx changed the title Use Rack constants Use Rack's Constants May 4, 2024
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@dblock dblock merged commit 3ae7b7a into ruby-grape:master May 4, 2024
44 checks passed
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