From eb13717c1b8fa8caae5b7dbd09c9a80c855450b3 Mon Sep 17 00:00:00 2001 From: Evan Raffel Date: Mon, 15 Jan 2024 15:50:48 -0500 Subject: [PATCH] Support headers passed in using string keys when Vary header is in a different case --- lib/faraday/http_cache/strategies/by_url.rb | 2 +- spec/strategies/by_url_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/faraday/http_cache/strategies/by_url.rb b/lib/faraday/http_cache/strategies/by_url.rb index dd60084..fad9090 100644 --- a/lib/faraday/http_cache/strategies/by_url.rb +++ b/lib/faraday/http_cache/strategies/by_url.rb @@ -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 diff --git a/spec/strategies/by_url_spec.rb b/spec/strategies/by_url_spec.rb index 301a2e3..a053d52 100644 --- a/spec/strategies/by_url_spec.rb +++ b/spec/strategies/by_url_spec.rb @@ -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