diff --git a/source/extensions/filters/http/cache/cacheability_utils.cc b/source/extensions/filters/http/cache/cacheability_utils.cc index 2b227f98fecae..9f142f5b1859f 100644 --- a/source/extensions/filters/http/cache/cacheability_utils.cc +++ b/source/extensions/filters/http/cache/cacheability_utils.cc @@ -26,9 +26,8 @@ const absl::flat_hash_set& cacheableStatusCodes() { const std::vector& conditionalHeaders() { // As defined by: https://httpwg.org/specs/rfc7232.html#preconditions. CONSTRUCT_ON_FIRST_USE( - std::vector, &Http::CustomHeaders::get().IfMatch, - &Http::CustomHeaders::get().IfNoneMatch, &Http::CustomHeaders::get().IfModifiedSince, - &Http::CustomHeaders::get().IfUnmodifiedSince, &Http::CustomHeaders::get().IfRange); + std::vector, &Http::CustomHeaders::get().IfNoneMatch, + &Http::CustomHeaders::get().IfModifiedSince, &Http::CustomHeaders::get().IfRange); } } // namespace @@ -36,11 +35,14 @@ bool CacheabilityUtils::canServeRequestFromCache(const Http::RequestHeaderMap& h const absl::string_view method = headers.getMethodValue(); const Http::HeaderValues& header_values = Http::Headers::get(); - // Check if the request contains any conditional headers. + // Check if the request contains any conditional headers other than if-unmodified-since + // or if-match. // For now, requests with conditional headers bypass the CacheFilter. // This behavior does not cause any incorrect results, but may reduce the cache effectiveness. // If needed to be handled properly refer to: // https://httpwg.org/specs/rfc7234.html#validation.received + // if-unmodified-since and if-match are ignored, as the spec explicitly says these + // header fields can be ignored by caches and intermediaries. for (auto conditional_header : conditionalHeaders()) { if (!headers.get(*conditional_header).empty()) { return false; diff --git a/test/extensions/filters/http/cache/cacheability_utils_test.cc b/test/extensions/filters/http/cache/cacheability_utils_test.cc index d43223f4075cb..f533f19365fea 100644 --- a/test/extensions/filters/http/cache/cacheability_utils_test.cc +++ b/test/extensions/filters/http/cache/cacheability_utils_test.cc @@ -94,8 +94,7 @@ TEST_F(CanServeRequestFromCacheTest, AuthorizationHeader) { } INSTANTIATE_TEST_SUITE_P(ConditionalHeaders, RequestConditionalHeadersTest, - testing::Values("if-match", "if-none-match", "if-modified-since", - "if-unmodified-since", "if-range"), + testing::Values("if-none-match", "if-modified-since", "if-range"), [](const auto& info) { std::string test_name = info.param; absl::c_replace_if(