Skip to content

Commit

Permalink
Make dig method case-insensitive in Faraday::Utils::Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
vitali-semenyuk authored and olleolleolle committed Apr 2, 2024
1 parent c0540b7 commit c9cc1b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/faraday/utils/headers.rb
Expand Up @@ -77,6 +77,12 @@ def delete(key)
super(key)
end

def dig(key, *rest)
key = KeyMap[key]
key = @names.fetch(key.downcase, key)
super(key, *rest)
end

def include?(key)
@names.include? key.downcase
end
Expand Down
9 changes: 9 additions & 0 deletions spec/faraday/utils/headers_spec.rb
Expand Up @@ -56,6 +56,15 @@
it { expect(subject.delete('content-type')).to be_nil }
end

describe '#dig' do
before { subject['Content-Type'] = 'application/json' }

it { expect(subject&.dig('Content-Type')).to eq('application/json') }
it { expect(subject&.dig('CONTENT-TYPE')).to eq('application/json') }
it { expect(subject&.dig(:content_type)).to eq('application/json') }
it { expect(subject&.dig('invalid')).to be_nil }
end

describe '#parse' do
context 'when response headers leave http status line out' do
let(:headers) { "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" }
Expand Down

0 comments on commit c9cc1b3

Please sign in to comment.