diff --git a/lib/response_bank/response_cache_handler.rb b/lib/response_bank/response_cache_handler.rb index c8fec9f..d1da4bd 100644 --- a/lib/response_bank/response_cache_handler.rb +++ b/lib/response_bank/response_cache_handler.rb @@ -113,7 +113,12 @@ def serving_from_noncurrent_but_recent_version_acceptable? end def serve_from_browser_cache(cache_key_hash) - if @env["HTTP_IF_NONE_MATCH"] == cache_key_hash + # Support for Etag variations including: + # If-None-Match: abc + # If-None-Match: "abc" + # If-None-Match: W/"abc" + # If-None-Match: "abc", "def" + if !@env["HTTP_IF_NONE_MATCH"].nil? && @env["HTTP_IF_NONE_MATCH"].include?(cache_key_hash) @env['cacheable.miss'] = false @env['cacheable.store'] = 'client' diff --git a/test/response_cache_handler_test.rb b/test/response_cache_handler_test.rb index 01ffcba..acb3d71 100644 --- a/test/response_cache_handler_test.rb +++ b/test/response_cache_handler_test.rb @@ -74,6 +74,18 @@ def test_client_cache_hit assert_env(false, 'client') end + def test_client_cache_hit_quoted + controller.request.env['HTTP_IF_NONE_MATCH'] = "\"#{handler.versioned_key_hash}\"" + handler.run! + assert_env(false, 'client') + end + + def test_client_cache_hit_weak + controller.request.env['HTTP_IF_NONE_MATCH'] = "W/\"#{handler.versioned_key_hash}\"" + handler.run! + assert_env(false, 'client') + end + def test_server_cache_hit controller.request.env['gzip'] = false @cache_store.expects(:read).with(handler.versioned_key_hash, raw: true).returns(page_serialized)