Skip to content

Commit 820e1ab

Browse files
committed
Added .rack3? method
1 parent 2d87076 commit 820e1ab

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

lib/grape.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def self.deprecator
4242
@deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Grape')
4343
end
4444

45+
def self.rack3?
46+
Gem::Version.new(::Rack.release) >= Gem::Version.new('3')
47+
end
48+
4549
eager_autoload do
4650
autoload :API
4751
autoload :Endpoint

lib/grape/http/headers.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ module Headers
1111
REQUEST_METHOD = 'REQUEST_METHOD'
1212
QUERY_STRING = 'QUERY_STRING'
1313

14-
if Gem::Version.new(Rack.release) < Gem::Version.new('3')
15-
ALLOW = 'Allow'
16-
CACHE_CONTROL = 'Cache-Control'
17-
CONTENT_LENGTH = 'Content-Length'
18-
CONTENT_TYPE = 'Content-Type'
19-
LOCATION = 'Location'
20-
TRANSFER_ENCODING = 'Transfer-Encoding'
21-
X_CASCADE = 'X-Cascade'
22-
else
14+
if Grape.rack3?
2315
ALLOW = 'allow'
2416
CACHE_CONTROL = 'cache-control'
2517
CONTENT_LENGTH = 'content-length'
2618
CONTENT_TYPE = 'content-type'
2719
LOCATION = 'location'
2820
TRANSFER_ENCODING = 'transfer-encoding'
2921
X_CASCADE = 'x-cascade'
22+
else
23+
ALLOW = 'Allow'
24+
CACHE_CONTROL = 'Cache-Control'
25+
CONTENT_LENGTH = 'Content-Length'
26+
CONTENT_TYPE = 'Content-Type'
27+
LOCATION = 'Location'
28+
TRANSFER_ENCODING = 'Transfer-Encoding'
29+
X_CASCADE = 'X-Cascade'
3030
end
3131

3232
GET = 'GET'

lib/grape/request.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ def build_headers
4646
end
4747
end
4848

49-
def transform_header(header)
50-
if Gem::Version.new(Rack.release) < Gem::Version.new('3')
51-
-header[5..].split('_').map(&:capitalize).join('-')
52-
else
49+
if Grape.rack3?
50+
def transform_header(header)
5351
-header[5..].tr('_', '-').downcase
5452
end
53+
else
54+
def transform_header(header)
55+
-header[5..].split('_').map(&:capitalize).join('-')
56+
end
5557
end
5658
end
5759
end

0 commit comments

Comments
 (0)