Skip to content

Commit

Permalink
Added .rack3? method
Browse files Browse the repository at this point in the history
  • Loading branch information
schinery committed Oct 23, 2023
1 parent 2d87076 commit 820e1ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def self.deprecator
@deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Grape')
end

def self.rack3?
Gem::Version.new(::Rack.release) >= Gem::Version.new('3')
end

eager_autoload do
autoload :API
autoload :Endpoint
Expand Down
18 changes: 9 additions & 9 deletions lib/grape/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ module Headers
REQUEST_METHOD = 'REQUEST_METHOD'
QUERY_STRING = 'QUERY_STRING'

if Gem::Version.new(Rack.release) < Gem::Version.new('3')
ALLOW = 'Allow'
CACHE_CONTROL = 'Cache-Control'
CONTENT_LENGTH = 'Content-Length'
CONTENT_TYPE = 'Content-Type'
LOCATION = 'Location'
TRANSFER_ENCODING = 'Transfer-Encoding'
X_CASCADE = 'X-Cascade'
else
if Grape.rack3?
ALLOW = 'allow'
CACHE_CONTROL = 'cache-control'
CONTENT_LENGTH = 'content-length'
CONTENT_TYPE = 'content-type'
LOCATION = 'location'
TRANSFER_ENCODING = 'transfer-encoding'
X_CASCADE = 'x-cascade'
else
ALLOW = 'Allow'
CACHE_CONTROL = 'Cache-Control'
CONTENT_LENGTH = 'Content-Length'
CONTENT_TYPE = 'Content-Type'
LOCATION = 'Location'
TRANSFER_ENCODING = 'Transfer-Encoding'
X_CASCADE = 'X-Cascade'
end

GET = 'GET'
Expand Down
10 changes: 6 additions & 4 deletions lib/grape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ def build_headers
end
end

def transform_header(header)
if Gem::Version.new(Rack.release) < Gem::Version.new('3')
-header[5..].split('_').map(&:capitalize).join('-')
else
if Grape.rack3?
def transform_header(header)
-header[5..].tr('_', '-').downcase
end
else
def transform_header(header)
-header[5..].split('_').map(&:capitalize).join('-')
end
end
end
end

0 comments on commit 820e1ab

Please sign in to comment.