diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java index 68b6573a4d..c774d62ec4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java @@ -421,6 +421,10 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { // Reset HTTP 1.0 Pragma header if present response.setHeader(HEADER_PRAGMA, ""); } + if (response.containsHeader(HEADER_EXPIRES)) { + // Reset HTTP 1.0 Expires header if present + response.setHeader(HEADER_EXPIRES, ""); + } } } @@ -545,6 +549,10 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { // HTTP 1.0 header response.setDateHeader(HEADER_EXPIRES, System.currentTimeMillis() + seconds * 1000L); } + else if (response.containsHeader(HEADER_EXPIRES)) { + // Reset HTTP 1.0 Expires header if present + response.setHeader(HEADER_EXPIRES, ""); + } if (this.useCacheControlHeader) { // HTTP 1.1 header diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java index a269583f9d..06a844e13a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java @@ -16,6 +16,7 @@ package org.springframework.web.servlet.mvc; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.*; import java.util.Properties; @@ -104,20 +105,21 @@ public class WebContentInterceptorTests { assertThat(cacheControlHeaders, Matchers.emptyIterable()); } - // SPR-13252 + // SPR-13252, SPR-14053 @Test public void cachingConfigAndPragmaHeader() throws Exception { WebContentInterceptor interceptor = new WebContentInterceptor(); interceptor.setCacheSeconds(10); response.setHeader("Pragma", "no-cache"); + response.setHeader("Expires", "0"); interceptor.preHandle(request, response, null); - Iterable pragmaHeaders = response.getHeaders("Pragma"); - assertThat(pragmaHeaders, Matchers.contains("")); + assertThat(response.getHeader("Pragma"), is("")); + assertThat(response.getHeader("Expires"), is("")); } - // SPR-13252 + // SPR-13252, SPR-14053 @SuppressWarnings("deprecation") @Test public void http10CachingConfigAndPragmaHeader() throws Exception { @@ -125,11 +127,12 @@ public class WebContentInterceptorTests { interceptor.setCacheSeconds(10); interceptor.setAlwaysMustRevalidate(true); response.setHeader("Pragma", "no-cache"); + response.setHeader("Expires", "0"); interceptor.preHandle(request, response, null); - Iterable pragmaHeaders = response.getHeaders("Pragma"); - assertThat(pragmaHeaders, Matchers.contains("")); + assertThat(response.getHeader("Pragma"), is("")); + assertThat(response.getHeader("Expires"), is("")); } @SuppressWarnings("deprecation")