Skip to content

Commit

Permalink
Changed .rack3? to .lowercase_headers?
Browse files Browse the repository at this point in the history
  • Loading branch information
schinery committed Oct 24, 2023
1 parent 1c69a74 commit 5f8ae61
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/grape/api/custom_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ 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

it 'includes headers passed as symbols' do
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
Expand Down
4 changes: 2 additions & 2 deletions spec/grape/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f8ae61

Please sign in to comment.