From 430a24e6bc9079192a0eabd4ac690f09361342a2 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 6 Jul 2023 09:37:00 +0200 Subject: [PATCH] Further document ShallowEtagHeaderFilter limitations This commit improves the documentation for the `ShallowEtagHeaderFilter`, stating that it is only meant to support a subset of conditional HTTP requests: GET requests with "If-None-Match" headers. Other headers and state changing HTTP methods are not supported here, as the filter only operates on the content of the response and has no knowledge of the resource being served. Closes gh-30517 --- framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc | 7 ++++--- .../web/filter/ShallowEtagHeaderFilter.java | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc index c6097bb03d5..8851bc74c24 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc @@ -69,9 +69,10 @@ written to the response and computing an MD5 hash from it. The next time a clien it does the same, but it also compares the computed value against the `If-None-Match` request header and, if the two are equal, returns a 304 (NOT_MODIFIED). -This strategy saves network bandwidth but not CPU, as the full response must be computed -for each request. Other strategies at the controller level, described earlier, can avoid -the computation. See xref:web/webmvc/mvc-caching.adoc[HTTP Caching]. +This strategy saves network bandwidth but not CPU, as the full response must be computed for each request. +State-changing HTTP methods and other HTTP conditional request headers such as `If-Match` and `If-Unmodified-Since` are outside the scope of this filter. +Other strategies at the controller level can avoid the computation and have a broader support for HTTP conditional requests. +See xref:web/webmvc/mvc-caching.adoc[HTTP Caching]. This filter has a `writeWeakETag` parameter that configures the filter to write weak ETags similar to the following: `W/"02a2d595e6ed9a0b24f027f2b63b134d6"` (as defined in diff --git a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java index b1e851a929d..a5dd68ac39f 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java @@ -46,6 +46,10 @@ import org.springframework.web.util.WebUtils; * (e.g. a {@link org.springframework.web.servlet.View}) is still rendered. * As such, this filter only saves bandwidth, not server performance. * + *

State-changing HTTP methods and other HTTP conditional request headers such as + * {@code If-Match} and {@code If-Unmodified-Since} are outside the scope of this filter. + * Please consider using {@link ServletWebRequest#checkNotModified(String, long)} instead. + * * @author Arjen Poutsma * @author Rossen Stoyanchev * @author Brian Clozel