diff --git a/lib/grape.rb b/lib/grape.rb index 680bea819f..f4ec5701fa 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -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 diff --git a/lib/grape/http/headers.rb b/lib/grape/http/headers.rb index 3014ccff0d..e8a368b82c 100644 --- a/lib/grape/http/headers.rb +++ b/lib/grape/http/headers.rb @@ -11,15 +11,7 @@ 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' @@ -27,6 +19,14 @@ module Headers 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' diff --git a/lib/grape/request.rb b/lib/grape/request.rb index 669f04f413..f522ea923b 100644 --- a/lib/grape/request.rb +++ b/lib/grape/request.rb @@ -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