Skip to content

Commit 1d35559

Browse files
authored
Merge pull request #1942 from ericproulx/retained_http_method
Retained Grape::Http::Headers in memory instead of new ones created.
2 parents d58dc0a + eceea52 commit 1d35559

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Features
44

55
* Your contribution here.
6+
* [#1942](https://github.com/ruby-grape/grape/pull/1942): Optimized retained memory methods - [@ericproulx](https://github.com/ericproulx).
67
* [#1941](https://github.com/ruby-grape/grape/pull/1941): Frozen string literal - [@ericproulx](https://github.com/ericproulx).
78
* [#1940](https://github.com/ruby-grape/grape/pull/1940): Get rid of a needless step in HashWithIndifferentAccess - [@dnesteryuk](https://github.com/dnesteryuk).
89
* [#1938](https://github.com/ruby-grape/grape/pull/1938): Add project metadata to the gemspec - [@orien](https://github.com/orien).

lib/grape/http/headers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ module Headers
2626
HTTP_ACCEPT = 'HTTP_ACCEPT'
2727

2828
FORMAT = 'format'
29+
30+
def self.find_supported_method(route_method)
31+
Grape::Http::Headers::SUPPORTED_METHODS.detect { |supported_method| supported_method.casecmp(route_method).zero? }
32+
end
2933
end
3034
end
3135
end

lib/grape/router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def compile!
4646
end
4747

4848
def append(route)
49-
map[route.request_method.to_s.upcase] << route
49+
map[route.request_method] << route
5050
end
5151

5252
def associate_routes(pattern, **options)

lib/grape/router/route.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ def route_path
6464
end
6565

6666
def initialize(method, pattern, **options)
67-
upcased_method = method.to_s.upcase
67+
method_s = method.to_s
68+
method_upcase = Grape::Http::Headers.find_supported_method(method_s) || method_s.upcase
6869

6970
@suffix = options[:suffix]
70-
@options = options.merge(method: upcased_method)
71+
@options = options.merge(method: method_upcase)
7172
@pattern = Pattern.new(pattern, **options)
72-
@translator = AttributeTranslator.new(**options, request_method: upcased_method)
73+
@translator = AttributeTranslator.new(**options, request_method: method_upcase)
7374
end
7475

7576
def exec(env)

0 commit comments

Comments
 (0)