Make dig method case-insensitive in Faraday::Utils::Headers

This commit is contained in:
Vitali Semenyuk 2024-04-01 15:24:16 +02:00 committed by Olle Jonsson
parent c0540b7ba3
commit c9cc1b30ec
2 changed files with 15 additions and 0 deletions

View File

@ -77,6 +77,12 @@ module Faraday
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

View File

@ -56,6 +56,15 @@ RSpec.describe Faraday::Utils::Headers do
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" }