Skip to content

Move HEAD route creation into Grape::Router::Route#to_head#2784

Merged
dblock merged 1 commit into
masterfrom
head_route_on_route_class
Jul 5, 2026
Merged

Move HEAD route creation into Grape::Router::Route#to_head#2784
dblock merged 1 commit into
masterfrom
head_route_on_route_class

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

Endpoint#mount_in built the HEAD variant of a GET route inline:

route.dup.then do |head_route|
  head_route.convert_to_head_request!
  router.append(head_route.apply(self))
end

Duplicating a route and turning it into a HEAD request is the route's own concern, not the endpoint's.

Change

  • Add Grape::Router::Route#to_head, which returns a fresh HEAD copy of the route.
  • Demote convert_to_head_request! to protectedto_head is now its only caller, and it calls it on the dup with an explicit receiver (which protected permits).
  • mount_in's loop body becomes router.append(route.to_head.apply(self)).

mount_in keeps the decision of whether to add a HEAD route (the do_not_route_head setting and the request_method != Rack::GET check) — that's the endpoint/router's call. to_head just builds the variant. The seam is: the endpoint decides, the route constructs.

Behavior is unchanged — HEAD on a GET route still 200s, do_not_route_head! still 405s on HEAD.

🤖 Generated with Claude Code

`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>
@ericproulx ericproulx force-pushed the head_route_on_route_class branch from ced6190 to 7cc4ae8 Compare July 5, 2026 19:09
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@dblock dblock merged commit c5e3b42 into master Jul 5, 2026
69 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