Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support headers passed in using string keys when Vary header is in a different case #137

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading