Skip to content

Commit bf9295b

Browse files
committed
ShallowEtagHeaderFilter skips "Cache-Control" header check on Servlet 2.5
Issue: SPR-12414
1 parent 74500ec commit bf9295b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.http.HttpMethod;
3131
import org.springframework.util.Assert;
32+
import org.springframework.util.ClassUtils;
3233
import org.springframework.util.DigestUtils;
3334
import org.springframework.util.ResizableByteArrayOutputStream;
3435
import org.springframework.util.StreamUtils;
@@ -60,6 +61,11 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
6061
private static final String DIRECTIVE_NO_STORE = "no-store";
6162

6263

64+
/** Checking for Servlet 3.0+ HttpServletResponse.getHeader(String) */
65+
private static final boolean responseGetHeaderAvailable =
66+
ClassUtils.hasMethod(HttpServletResponse.class, "getHeader", String.class);
67+
68+
6369
/**
6470
* The default value is "false" so that the filter may delay the generation of
6571
* an ETag until the last asynchronously dispatched thread.
@@ -150,7 +156,7 @@ protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletRespo
150156

151157
if (responseStatusCode >= 200 && responseStatusCode < 300 &&
152158
HttpMethod.GET.name().equals(request.getMethod())) {
153-
String cacheControl = response.getHeader(HEADER_CACHE_CONTROL);
159+
String cacheControl = (responseGetHeaderAvailable ? response.getHeader(HEADER_CACHE_CONTROL) : null);
154160
if (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE)) {
155161
return true;
156162
}

0 commit comments

Comments
 (0)