Move HEAD route creation into Grape::Router::Route#to_head#2784
Merged
Conversation
`Endpoint#mount_in` built the HEAD variant of a GET route inline: dup the route, flip its request method, then apply and append it. Duplicating a route and turning it into a HEAD request is the route's own concern, not the endpoint's. Add `Route#to_head`, which returns a fresh HEAD copy of the route, and demote `convert_to_head_request!` to `protected` now that `to_head` is its only caller. `mount_in` keeps the decision of whether to add a HEAD route (the `do_not_route_head` setting and the GET check) and just calls `route.to_head.apply(self)`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ced6190 to
7cc4ae8
Compare
Danger ReportNo issues found. |
dblock
approved these changes
Jul 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Endpoint#mount_inbuilt the HEAD variant of a GET route inline:Duplicating a route and turning it into a HEAD request is the route's own concern, not the endpoint's.
Change
Grape::Router::Route#to_head, which returns a fresh HEAD copy of the route.convert_to_head_request!toprotected—to_headis now its only caller, and it calls it on the dup with an explicit receiver (whichprotectedpermits).mount_in's loop body becomesrouter.append(route.to_head.apply(self)).mount_inkeeps the decision of whether to add a HEAD route (thedo_not_route_headsetting and therequest_method != Rack::GETcheck) — that's the endpoint/router's call.to_headjust builds the variant. The seam is: the endpoint decides, the route constructs.Behavior is unchanged —
HEADon a GET route still 200s,do_not_route_head!still 405s onHEAD.🤖 Generated with Claude Code