Skip to content

Commit 0a88e94

Browse files
committed
Added .rack3? method
1 parent 2d87076 commit 0a88e94

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
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

spec/support/headers_helpers.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,7 @@ module Spec
44
module Support
55
module Helpers
66
def rack_versioned_headers
7-
if Gem::Version.new(Rack.release) < Gem::Version.new('3')
8-
{
9-
cache_control: 'Cache-Control',
10-
content_length: 'Content-Length',
11-
content_type: 'Content-Type',
12-
grape_likes_symbolic: 'Grape-Likes-Symbolic',
13-
location: 'Location',
14-
symbol_header: 'Symbol-Header',
15-
transfer_encoding: 'Transfer-Encoding',
16-
x_access_token: 'X-Access-Token',
17-
x_cascade: 'X-Cascade',
18-
x_grape_client: 'X-Grape-Client',
19-
x_grape_is_cool: 'X-Grape-Is-Cool'
20-
}
21-
else
7+
if Grape.rack3?
228
{
239
cache_control: 'cache-control',
2410
content_length: 'content-length',
@@ -32,6 +18,21 @@ def rack_versioned_headers
3218
x_grape_client: 'x-grape-client',
3319
x_grape_is_cool: 'x-grape-is-cool'
3420
}
21+
else
22+
{
23+
cache_control: 'Cache-Control',
24+
content_length: 'Content-Length',
25+
content_type: 'Content-Type',
26+
grape_likes_symbolic: 'Grape-Likes-Symbolic',
27+
location: 'Location',
28+
symbol_header: 'Symbol-Header',
29+
transfer_encoding: 'Transfer-Encoding',
30+
x_access_token: 'X-Access-Token',
31+
x_cascade: 'X-Cascade',
32+
x_grape_client: 'X-Grape-Client',
33+
x_grape_is_cool: 'X-Grape-Is-Cool'
34+
}
35+
3536
end
3637
end
3738
end

0 commit comments

Comments
 (0)