From 5f8ae61085cd2772f6e9d85ab1404d03405cc726 Mon Sep 17 00:00:00 2001 From: Stuart Chinery Date: Tue, 24 Oct 2023 22:07:45 +0100 Subject: [PATCH] Changed .rack3? to .lowercase_headers? --- lib/grape.rb | 4 ++-- lib/grape/http/headers.rb | 2 +- lib/grape/request.rb | 2 +- spec/grape/api/custom_validations_spec.rb | 4 ++-- spec/grape/endpoint_spec.rb | 4 ++-- spec/grape/request_spec.rb | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/grape.rb b/lib/grape.rb index f4ec5701fa..cb36ebd1df 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -42,8 +42,8 @@ def self.deprecator @deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Grape') end - def self.rack3? - Gem::Version.new(::Rack.release) >= Gem::Version.new('3') + def self.lowercase_headers? + Rack::CONTENT_TYPE == 'content-type' end eager_autoload do diff --git a/lib/grape/http/headers.rb b/lib/grape/http/headers.rb index 442f6b65cc..eb6a1c3ff0 100644 --- a/lib/grape/http/headers.rb +++ b/lib/grape/http/headers.rb @@ -11,7 +11,7 @@ module Headers REQUEST_METHOD = 'REQUEST_METHOD' QUERY_STRING = 'QUERY_STRING' - if Grape.rack3? + if Grape.lowercase_headers? ALLOW = 'allow' CACHE_CONTROL = 'cache-control' CONTENT_LENGTH = 'content-length' diff --git a/lib/grape/request.rb b/lib/grape/request.rb index f522ea923b..c907f0b4ab 100644 --- a/lib/grape/request.rb +++ b/lib/grape/request.rb @@ -46,7 +46,7 @@ def build_headers end end - if Grape.rack3? + if Grape.lowercase_headers? def transform_header(header) -header[5..].tr('_', '-').downcase end diff --git a/spec/grape/api/custom_validations_spec.rb b/spec/grape/api/custom_validations_spec.rb index 121e44f918..a6b7a629c1 100644 --- a/spec/grape/api/custom_validations_spec.rb +++ b/spec/grape/api/custom_validations_spec.rb @@ -169,12 +169,12 @@ def validate(request) end def access_header - Grape.rack3? ? 'x-access-token' : 'X-Access-Token' + Grape.lowercase_headers? ? 'x-access-token' : 'X-Access-Token' end end end let(:app) { Rack::Builder.new(subject) } - let(:x_access_token_header) { Grape.rack3? ? 'x-access-token' : 'X-Access-Token' } + let(:x_access_token_header) { Grape.lowercase_headers? ? 'x-access-token' : 'X-Access-Token' } before do described_class.register_validator('admin', admin_validator) diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index e81fbc806d..b83c25dda6 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -146,7 +146,7 @@ def app it 'includes additional request headers' do get '/headers', nil, 'HTTP_X_GRAPE_CLIENT' => '1' - x_grape_client_header = Grape.rack3? ? 'x-grape-client' : 'X-Grape-Client' + x_grape_client_header = Grape.lowercase_headers? ? 'x-grape-client' : 'X-Grape-Client' expect(JSON.parse(last_response.body)[x_grape_client_header]).to eq('1') end @@ -154,7 +154,7 @@ def app env = Rack::MockRequest.env_for('/headers') env[:HTTP_SYMBOL_HEADER] = 'Goliath passes symbols' body = read_chunks(subject.call(env)[2]).join - symbol_header = Grape.rack3? ? 'symbol-header' : 'Symbol-Header' + symbol_header = Grape.lowercase_headers? ? 'symbol-header' : 'Symbol-Header' expect(JSON.parse(body)[symbol_header]).to eq('Goliath passes symbols') end end diff --git a/spec/grape/request_spec.rb b/spec/grape/request_spec.rb index 3c0c9e2de3..b84b6dffdc 100644 --- a/spec/grape/request_spec.rb +++ b/spec/grape/request_spec.rb @@ -90,7 +90,7 @@ module Grape } end let(:x_grape_is_cool_header) do - Grape.rack3? ? 'x-grape-is-cool' : 'X-Grape-Is-Cool' + Grape.lowercase_headers? ? 'x-grape-is-cool' : 'X-Grape-Is-Cool' end it 'cuts HTTP_ prefix and capitalizes header name words' do @@ -120,7 +120,7 @@ module Grape default_env.merge(request_headers) end let(:grape_likes_symbolic_header) do - Grape.rack3? ? 'grape-likes-symbolic' : 'Grape-Likes-Symbolic' + Grape.lowercase_headers? ? 'grape-likes-symbolic' : 'Grape-Likes-Symbolic' end it 'converts them to string' do