Skip to content

Commit

Permalink
Support headers passed in using string keys when Vary header is in a …
Browse files Browse the repository at this point in the history
…different case (#137)
  • Loading branch information
evman182 committed Jan 15, 2024
1 parent d05c590 commit 016cf1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/faraday/http_cache/strategies/by_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def vary_matches?(cached_response, request, cached_request)
vary = headers['Vary'].to_s

vary.empty? || (vary != '*' && vary.split(/[\s,]+/).all? do |header|
request.headers[header] == cached_request[:headers][header]
request.headers[header] == (cached_request[:headers][header] || cached_request[:headers][header.downcase])
end)
end

Expand Down
18 changes: 18 additions & 0 deletions spec/strategies/by_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@

expect(subject.read(request)).to be_a(Faraday::HttpCache::Response)
end

context 'with a Vary header in the response in a different case than the matching request header' do
let(:request) do
Faraday::HttpCache::Request.new(
method: :get,
url: 'http://test/index',
headers: Faraday::Utils::Headers.new({ 'accept' => 'application/json' })
)
end
let(:response) do
Faraday::HttpCache::Response.new(response_headers: Faraday::Utils::Headers.new({ vary: 'Accept' }))
end

it 'reads stored message' do
subject.write(request, response)
expect(subject.read(request)).to be_a(Faraday::HttpCache::Response)
end
end
end

context 'with the JSON serializer' do
Expand Down

0 comments on commit 016cf1f

Please sign in to comment.