Skip to content

Commit

Permalink
Use dup instead of new for Head Route
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Nov 2, 2024
1 parent d0da869 commit 6a20afb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def mount_in(router)
routes.each do |route|
router.append(route.apply(self))
if !namespace_inheritable(:do_not_route_head) && route.request_method == Rack::GET
Grape::Router::Route.new(Rack::HEAD, route.origin, route.attributes).then do |head_route|
route.dup.then do |head_route|
head_route.convert_to_head_request!
router.append(head_route.apply(self))
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/grape/router/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def initialize(method, pattern, options)
super(options)
end

def convert_to_head_request!
@request_method = Rack::HEAD
end

def exec(env)
@app.call(env)
end
Expand Down

0 comments on commit 6a20afb

Please sign in to comment.