Relax SPR-13867 changes for ResourceHttpRequestHandler

Prior to this change, SPR-13867 made sure that any class extending
WebContentGenerator would not overwrite existing HTTP "Cache-Control"
response headers - set by a filter, a Controller handler, etc.

This caused issues with resource handling, since specifying a cache
configuration there would not overwrite default headers set by filters,
for example by Spring Security.

This commit restricts the previous changes to the
RequestMappingHandlerAdapter, in order to avoid overwriting header set
by a filter or a Controller handler in those cases.

Issue: SPR-14005
Cherry-picked from 50bcd67fb6
This commit is contained in:
Brian Clozel
2016-03-02 16:53:24 +01:00
parent 8a44560d82
commit 0ef90df120
3 changed files with 47 additions and 38 deletions

View File

@@ -503,6 +503,17 @@ public class ResourceHttpRequestHandlerTests {
assertEquals(0, this.response.getContentLength());
}
// SPR-14005
@Test
public void doOverwriteExistingCacheControlHeaders() throws Exception {
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
this.response.setHeader("Cache-Control", "no-store");
this.handler.handleRequest(this.request, this.response);
assertEquals("max-age=3600", this.response.getHeader("Cache-Control"));
}
private long dateHeaderAsLong(String responseHeaderName) throws Exception {
return dateFormat.parse(this.response.getHeader(responseHeaderName)).getTime();