@Test @SuppressWarnings("deprecation") public void getResourceHttp10BehaviorCache() throws Exception { this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css"); this.handler.setCacheSeconds(3600); this.handler.setUseExpiresHeader(true); this.handler.setUseCacheControlHeader(true); this.handler.setAlwaysMustRevalidate(true); this.handler.handleRequest(this.request, this.response); assertEquals("max-age=3600, must-revalidate", this.response.getHeader("Cache-Control")); assertTrue(this.response.getDateHeader("Expires") >= System.currentTimeMillis() - 1000 + (3600 * 1000)); assertTrue(this.response.containsHeader("Last-Modified")); assertEquals(resourceLastModified("test/foo.css") / 1000, this.response.getDateHeader("Last-Modified") / 1000); assertEquals("bytes", this.response.getHeader("Accept-Ranges")); assertEquals(1, this.response.getHeaders("Accept-Ranges").size()); }
@Test @SuppressWarnings("deprecation") public void getResourceHttp10BehaviorNoCache() throws Exception { this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css"); this.handler.setCacheSeconds(0); this.handler.setUseExpiresHeader(true); this.handler.setUseCacheControlNoStore(false); this.handler.setUseCacheControlHeader(true); this.handler.handleRequest(this.request, this.response); assertEquals("no-cache", this.response.getHeader("Pragma")); assertThat(this.response.getHeaderValues("Cache-Control"), Matchers.iterableWithSize(1)); assertEquals("no-cache", this.response.getHeader("Cache-Control")); assertTrue(this.response.getDateHeader("Expires") <= System.currentTimeMillis()); assertTrue(this.response.containsHeader("Last-Modified")); assertEquals(resourceLastModified("test/foo.css") / 1000, this.response.getDateHeader("Last-Modified") / 1000); assertEquals("bytes", this.response.getHeader("Accept-Ranges")); assertEquals(1, this.response.getHeaders("Accept-Ranges").size()); }