private void ensure206ContainsDateHeader(final HttpResponse response) { if (response.getFirstHeader(HttpHeaders.DATE) == null) { response.addHeader(HttpHeaders.DATE, DateUtils.formatDate(new Date())); } }
@Override public AsyncDataConsumer handleResponse( final HttpResponse backendResponse, final EntityDetails entityDetails) throws HttpException, IOException { final Date responseDate = getCurrentDate(); backendResponse.addHeader("Via", generateViaHeader(backendResponse)); final AsyncExecCallback callback = new BackendResponseHandler(target, request, requestDate, responseDate, scope, asyncExecCallback); callbackRef.set(callback); return callback.handleResponse(backendResponse, entityDetails); }
@Test public void testIsGetWithNoStoreCacheable() { response.addHeader("Cache-Control", "no-store"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() { policy = new ResponseCachingPolicy(0, true, false, false); request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); response.setHeader("Cache-Control", "public"); response.addHeader("Age", "3"); response.addHeader("Age", "5"); Assert.assertFalse(policy.isResponseCacheable(request, response)); }
@Test public void testIsHeadWithNoStoreCacheable() { response.addHeader("Cache-Control", "no-store"); Assert.assertFalse(policy.isResponseCacheable("HEAD", response)); }
@Test public void testIsGetWithNoStoreEmbeddedInListCacheable() { response.addHeader("Cache-Control", "public, no-store"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testIsGetWithNoCacheEmbeddedInListCacheable() { response.addHeader("Cache-Control", "public, no-cache"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testIsHeadWithNoCacheEmbeddedInListCacheable() { response.addHeader("Cache-Control", "public, no-cache"); Assert.assertFalse(policy.isResponseCacheable("HEAD", response)); }
@Test public void testIsHeadWithNoCacheCacheable() { response.addHeader("Cache-Control", "no-cache"); Assert.assertFalse(policy.isResponseCacheable("HEAD", response)); }
@Test public void testIsGetWithVaryHeaderCacheable() { response.addHeader("Vary", "Accept-Encoding"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testResponsesWithMalformedDateHeadersAreNotCacheable() { response.addHeader("Date", "garbage"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testIsGetWithAnyCacheControlCacheable() { response.addHeader("Cache-Control", "max=10"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); response = new BasicHttpResponse(HttpStatus.SC_OK, ""); response.setHeader("Date", DateUtils.formatDate(new Date())); response.addHeader("Cache-Control", "no-transform"); response.setHeader("Content-Length", "0"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() { policy = new ResponseCachingPolicy(0, true, false, false); request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); response.setHeader("Cache-Control", "public"); response.addHeader("Expires", DateUtils.formatDate(now)); response.addHeader("Expires", DateUtils.formatDate(sixSecondsAgo)); Assert.assertFalse(policy.isResponseCacheable(request, response)); }
@Test public void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() { policy = new ResponseCachingPolicy(0, true, false, false); request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); response.setHeader("Cache-Control", "public"); response.addHeader("Date", DateUtils.formatDate(now)); response.addHeader("Date", DateUtils.formatDate(sixSecondsAgo)); Assert.assertFalse(policy.isResponseCacheable(request, response)); }
@Test public void testIsHeadWithAnyCacheControlCacheable() { policy = new ResponseCachingPolicy(0, true, false, false); response.addHeader("Cache-Control", "max=10"); Assert.assertTrue(policy.isResponseCacheable("HEAD", response)); response = new BasicHttpResponse(HttpStatus.SC_OK, ""); response.setHeader("Date", DateUtils.formatDate(new Date())); response.addHeader("Cache-Control", "no-transform"); response.setHeader("Content-Length", "0"); Assert.assertTrue(policy.isResponseCacheable("HEAD", response)); }