hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f.@apache.org
Subject svn commit: r1553642 [1/2] - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Fri, 27 Dec 2013 08:18:03 GMT
Author: fx
Date: Fri Dec 27 08:18:03 2013
New Revision: 1553642

URL: http://svn.apache.org/r1553642
Log:
HTTPCLIENT-1443: HttpCache uses the physical host instead of the virtual host in the cache key

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java?rev=1553642&r1=1553641&r2=1553642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java Fri Dec 27 08:18:03 2013
@@ -96,7 +96,7 @@ class AsynchronousValidator implements C
             final HttpExecutionAware execAware,
             final HttpCacheEntry entry) {
         // getVariantURI will fall back on getURI if no variants exist
-        final String uri = cacheKeyGenerator.getVariantURI(route.getTargetHost(), request, entry);
+        final String uri = cacheKeyGenerator.getVariantURI(context.getTargetHost(), request, entry);
 
         if (!queued.contains(uri)) {
             final int consecutiveFailedAttempts = failureCache.getErrorCount(uri);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java?rev=1553642&r1=1553641&r2=1553642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java Fri Dec 27 08:18:03 2013
@@ -231,7 +231,7 @@ public class CachingExec implements Clie
             final HttpClientContext context,
             final HttpExecutionAware execAware) throws IOException, HttpException {
 
-        final HttpHost target = route.getTargetHost();
+        final HttpHost target = context.getTargetHost();
         final String via = generateViaHeader(request.getOriginal());
 
         // default response context
@@ -250,7 +250,7 @@ public class CachingExec implements Clie
         requestCompliance.makeRequestCompliant(request);
         request.addHeader("Via",via);
 
-        flushEntriesInvalidatedByRequest(route.getTargetHost(), request);
+        flushEntriesInvalidatedByRequest(context.getTargetHost(), request);
 
         if (!cacheableRequestPolicy.isServableFromCache(request)) {
             log.debug("Request is not servable from cache");
@@ -272,7 +272,7 @@ public class CachingExec implements Clie
             final HttpClientContext context,
             final HttpExecutionAware execAware,
             final HttpCacheEntry entry) throws IOException, HttpException {
-        final HttpHost target = route.getTargetHost();
+        final HttpHost target = context.getTargetHost();
         recordCacheHit(target, request);
         CloseableHttpResponse out = null;
         final Date now = getCurrentDate();
@@ -326,7 +326,7 @@ public class CachingExec implements Clie
             final HttpRequestWrapper request,
             final HttpClientContext context,
             final HttpExecutionAware execAware) throws IOException, HttpException {
-        final HttpHost target = route.getTargetHost();
+        final HttpHost target = context.getTargetHost();
         recordCacheMiss(target, request);
 
         if (!mayCallBackend(request)) {
@@ -659,12 +659,12 @@ public class CachingExec implements Clie
             recordCacheUpdate(context);
 
             final HttpCacheEntry responseEntry = getUpdatedVariantEntry(
-                    route.getTargetHost(), conditionalRequest, requestDate, responseDate,
+                context.getTargetHost(), conditionalRequest, requestDate, responseDate,
                     backendResponse, matchingVariant, matchedEntry);
             backendResponse.close();
 
             final CloseableHttpResponse resp = responseGenerator.generateResponse(responseEntry);
-            tryToUpdateVariantMap(route.getTargetHost(), request, matchingVariant);
+            tryToUpdateVariantMap(context.getTargetHost(), request, matchingVariant);
 
             if (shouldSendNotModifiedResponse(request, responseEntry)) {
                 return responseGenerator.generateNotModifiedResponse(responseEntry);
@@ -760,7 +760,7 @@ public class CachingExec implements Clie
 
         if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
             final HttpCacheEntry updatedEntry = responseCache.updateCacheEntry(
-                    route.getTargetHost(), request, cacheEntry,
+                    context.getTargetHost(), request, cacheEntry,
                     backendResponse, requestDate, responseDate);
             if (suitabilityChecker.isConditional(request)
                     && suitabilityChecker.allConditionalsMatch(request, updatedEntry, new Date())) {
@@ -805,7 +805,7 @@ public class CachingExec implements Clie
         log.trace("Handling Backend response");
         responseCompliance.ensureProtocolCompliance(request, backendResponse);
 
-        final HttpHost target = route.getTargetHost();
+        final HttpHost target = context.getTargetHost();
         final boolean cacheable = responseCachingPolicy.isResponseCacheable(request, backendResponse);
         responseCache.flushInvalidatedCacheEntriesFor(target, request, backendResponse);
         if (cacheable && !alreadyHaveNewerCacheEntry(target, request, backendResponse)) {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java?rev=1553642&r1=1553641&r2=1553642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java Fri Dec 27 08:18:03 2013
@@ -88,6 +88,7 @@ public abstract class AbstractProtocolTe
         request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
 
         context = HttpCacheContext.create();
+        context.setTargetHost(host);
 
         originResponse = Proxies.enhanceResponse(HttpTestUtils.make200Response());
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java?rev=1553642&r1=1553641&r2=1553642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java Fri Dec 27 08:18:03 2013
@@ -66,6 +66,7 @@ public class TestAsynchronousValidator {
         route = new HttpRoute(new HttpHost("foo.example.com"));
         request = HttpRequestWrapper.wrap(new HttpGet("/"));
         context = HttpClientContext.create();
+        context.setTargetHost(new HttpHost("foo.example.com"));
         mockExecAware = EasyMock.createNiceMock(HttpExecutionAware.class);
         mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
         mockSchedulingStrategy = EasyMock.createNiceMock(SchedulingStrategy.class);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java?rev=1553642&r1=1553641&r2=1553642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java Fri Dec 27 08:18:03 2013
@@ -140,39 +140,28 @@ public abstract class TestCachingExecCha
 
         host = new HttpHost("foo.example.com");
         route = new HttpRoute(host);
-        request = HttpRequestWrapper.wrap(
-                new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_1));
+        request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/stuff",
+            HttpVersion.HTTP_1_1));
         context = HttpCacheContext.create();
+        context.setTargetHost(host);
         entry = HttpTestUtils.makeCacheEntry();
-        impl = createCachingExecChain(
-                mockBackend,
-                mockCache,
-                mockValidityPolicy,
-                mockResponsePolicy,
-                mockResponseGenerator,
-                mockRequestPolicy,
-                mockSuitabilityChecker,
-                mockConditionalRequestBuilder,
-                mockResponseProtocolCompliance,
-                mockRequestProtocolCompliance,
-                config,
-                asyncValidator);
-    }
-
-    public abstract ClientExecChain createCachingExecChain(
-            ClientExecChain backend, HttpCache responseCache,
-            CacheValidityPolicy validityPolicy,
-            ResponseCachingPolicy responseCachingPolicy,
-            CachedHttpResponseGenerator responseGenerator,
-            CacheableRequestPolicy cacheableRequestPolicy,
-            CachedResponseSuitabilityChecker suitabilityChecker,
-            ConditionalRequestBuilder conditionalRequestBuilder,
-            ResponseProtocolCompliance responseCompliance,
-            RequestProtocolCompliance requestCompliance, CacheConfig config,
-            AsynchronousValidator asynchRevalidator);
+        impl = createCachingExecChain(mockBackend, mockCache, mockValidityPolicy,
+            mockResponsePolicy, mockResponseGenerator, mockRequestPolicy, mockSuitabilityChecker,
+            mockConditionalRequestBuilder, mockResponseProtocolCompliance,
+            mockRequestProtocolCompliance, config, asyncValidator);
+    }
+
+    public abstract ClientExecChain createCachingExecChain(ClientExecChain backend,
+        HttpCache responseCache, CacheValidityPolicy validityPolicy,
+        ResponseCachingPolicy responseCachingPolicy, CachedHttpResponseGenerator responseGenerator,
+        CacheableRequestPolicy cacheableRequestPolicy,
+        CachedResponseSuitabilityChecker suitabilityChecker,
+        ConditionalRequestBuilder conditionalRequestBuilder,
+        ResponseProtocolCompliance responseCompliance, RequestProtocolCompliance requestCompliance,
+        CacheConfig config, AsynchronousValidator asynchRevalidator);
 
-    public abstract ClientExecChain createCachingExecChain(
-            ClientExecChain backend, HttpCache cache, CacheConfig config);
+    public abstract ClientExecChain createCachingExecChain(ClientExecChain backend,
+        HttpCache cache, CacheConfig config);
 
     public static HttpRequestWrapper eqRequest(final HttpRequestWrapper in) {
         EasyMock.reportMatcher(new RequestEquivalent(in));
@@ -230,7 +219,7 @@ public abstract class TestCachingExecCha
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
         final HttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Cache-Control","max-age=3600");
+        resp1.setHeader("Cache-Control", "max-age=3600");
 
         backendExpectsAnyRequestAndReturn(resp1);
 
@@ -257,11 +246,11 @@ public abstract class TestCachingExecCha
         backendExpectsAnyRequestAndReturn(resp1);
 
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
-        req2.setHeader("Cache-Control","no-cache");
+        req2.setHeader("Cache-Control", "no-cache");
         final HttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("ETag", "\"old-etag\"");
         resp2.setHeader("Date", DateUtils.formatDate(fiveSecondsAgo));
-        resp2.setHeader("Cache-Control","max-age=3600");
+        resp2.setHeader("Cache-Control", "max-age=3600");
 
         backendExpectsAnyRequestAndReturn(resp2);
 
@@ -291,11 +280,11 @@ public abstract class TestCachingExecCha
         backendExpectsAnyRequestAndReturn(resp1);
 
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
-        req2.setHeader("Cache-Control","max-age=0");
+        req2.setHeader("Cache-Control", "max-age=0");
         final HttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("ETag", "\"new-etag\"");
         resp2.setHeader("Date", DateUtils.formatDate(now));
-        resp2.setHeader("Cache-Control","max-age=3600");
+        resp2.setHeader("Cache-Control", "max-age=3600");
 
         backendExpectsAnyRequestAndReturn(resp2);
 
@@ -315,9 +304,8 @@ public abstract class TestCachingExecCha
         if (error != null) {
             errors.add(error);
         }
-        expect(
-                mockRequestProtocolCompliance.requestIsFatallyNonCompliant(eqRequest(request))).andReturn(
-                errors);
+        expect(mockRequestProtocolCompliance.requestIsFatallyNonCompliant(eqRequest(request)))
+            .andReturn(errors);
     }
 
     @Test
@@ -340,11 +328,12 @@ public abstract class TestCachingExecCha
     @Test
     public void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception {
         final CacheConfig config = CacheConfig.DEFAULT;
-        impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(), mockStorage, config), config);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(),
+            mockStorage, config), config);
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
         final HttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Cache-Control","no-cache");
+        resp1.setHeader("Cache-Control", "no-cache");
 
         expect(mockStorage.getEntry(isA(String.class))).andReturn(null).anyTimes();
         mockStorage.removeEntry(isA(String.class));
@@ -380,7 +369,7 @@ public abstract class TestCachingExecCha
         final ClientProtocolException expected = new ClientProtocolException("ouch");
 
         requestIsFatallyNonCompliant(null);
-        mockRequestProtocolCompliance.makeRequestCompliant((HttpRequestWrapper)anyObject());
+        mockRequestProtocolCompliance.makeRequestCompliant((HttpRequestWrapper) anyObject());
         expectLastCall().andThrow(expected);
 
         boolean gotException = false;
@@ -396,38 +385,40 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse()
-        throws Exception {
+    public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1));
-        req.setHeader("Max-Forwards","0");
+        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS", "*",
+            HttpVersion.HTTP_1_1));
+        req.setHeader("Max-Forwards", "0");
 
         impl.execute(route, req, context, null);
         Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE,
-                context.getCacheResponseStatus());
+            context.getCacheResponseStatus());
     }
 
     @Test
     public void testSetsModuleGeneratedResponseContextForFatallyNoncompliantRequest()
         throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        req.setHeader("Range","bytes=0-50");
-        req.setHeader("If-Range","W/\"weak-etag\"");
+        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        req.setHeader("Range", "bytes=0-50");
+        req.setHeader("If-Range", "W/\"weak-etag\"");
 
         impl.execute(route, req, context, null);
         Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE,
-                context.getCacheResponseStatus());
+            context.getCacheResponseStatus());
     }
 
     @Test
     public void testRecordsClientProtocolInViaHeaderIfRequestNotServableFromCache()
         throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req = HttpRequestWrapper.wrap(
-                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0));
-        req.setHeader("Cache-Control","no-cache");
-        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content");
+        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/",
+            HttpVersion.HTTP_1_0));
+        req.setHeader("Cache-Control", "no-cache");
+        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NO_CONTENT, "No Content");
         final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
 
         backendCaptureRequestAndReturn(cap, resp);
@@ -439,34 +430,34 @@ public abstract class TestCachingExecCha
         final HttpRequest captured = cap.getValue();
         final String via = captured.getFirstHeader("Via").getValue();
         final String proto = via.split("\\s+")[0];
-        Assert.assertTrue("http/1.0".equalsIgnoreCase(proto) ||
-                "1.0".equalsIgnoreCase(proto));
+        Assert.assertTrue("http/1.0".equalsIgnoreCase(proto) || "1.0".equalsIgnoreCase(proto));
     }
 
     @Test
-    public void testSetsCacheMissContextIfRequestNotServableFromCache()
-        throws Exception {
+    public void testSetsCacheMissContextIfRequestNotServableFromCache() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        req.setHeader("Cache-Control","no-cache");
-        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content");
+        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        req.setHeader("Cache-Control", "no-cache");
+        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NO_CONTENT, "No Content");
 
         backendExpectsAnyRequestAndReturn(resp);
 
         replayMocks();
         impl.execute(route, req, context, null);
         verifyMocks();
-        Assert.assertEquals(CacheResponseStatus.CACHE_MISS,
-                context.getCacheResponseStatus());
+        Assert.assertEquals(CacheResponseStatus.CACHE_MISS, context.getCacheResponseStatus());
     }
 
     @Test
-    public void testSetsViaHeaderOnResponseIfRequestNotServableFromCache()
-            throws Exception {
+    public void testSetsViaHeaderOnResponseIfRequestNotServableFromCache() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        req.setHeader("Cache-Control","no-cache");
-        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content");
+        final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        req.setHeader("Cache-Control", "no-cache");
+        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NO_CONTENT, "No Content");
 
         backendExpectsAnyRequestAndReturn(resp);
 
@@ -477,16 +468,17 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testSetsViaHeaderOnResponseForCacheMiss()
-        throws Exception {
+    public void testSetsViaHeaderOnResponseForCacheMiss() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(new Date()));
-        resp1.setHeader("Cache-Control","public, max-age=3600");
+        resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         backendExpectsAnyRequestAndReturn(resp1);
 
@@ -497,17 +489,19 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testSetsCacheHitContextIfRequestServedFromCache()
-        throws Exception {
+    public void testSetsCacheHitContextIfRequestServedFromCache() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(new Date()));
-        resp1.setHeader("Cache-Control","public, max-age=3600");
+        resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         backendExpectsAnyRequestAndReturn(resp1);
 
@@ -515,22 +509,23 @@ public abstract class TestCachingExecCha
         impl.execute(route, req1, context, null);
         impl.execute(route, req2, context, null);
         verifyMocks();
-        Assert.assertEquals(CacheResponseStatus.CACHE_HIT,
-                context.getCacheResponseStatus());
+        Assert.assertEquals(CacheResponseStatus.CACHE_HIT, context.getCacheResponseStatus());
     }
 
     @Test
-    public void testSetsViaHeaderOnResponseIfRequestServedFromCache()
-        throws Exception {
+    public void testSetsViaHeaderOnResponseIfRequestServedFromCache() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(new Date()));
-        resp1.setHeader("Cache-Control","public, max-age=3600");
+        resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         backendExpectsAnyRequestAndReturn(resp1);
 
@@ -542,16 +537,17 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns304ForIfModifiedSinceHeaderIfRequestServedFromCache()
-            throws Exception {
+    public void testReturns304ForIfModifiedSinceHeaderIfRequestServedFromCache() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -575,28 +571,28 @@ public abstract class TestCachingExecCha
         final Date oneHourAgo = new Date(now.getTime() - 3600 * 1000L);
         final Date inTenMinutes = new Date(now.getTime() + 600 * 1000L);
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req1.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp1.setHeader("Date", DateUtils.formatDate(now));
         resp1.setHeader("Cache-control", "max-age=600");
         resp1.setHeader("Expires", DateUtils.formatDate(inTenMinutes));
 
-        expect(mockBackend.execute(
-            eq(route),
-            isA(HttpRequestWrapper.class),
-            isA(HttpClientContext.class),
-            (HttpExecutionAware) isNull())).andReturn(Proxies.enhanceResponse(resp1)).once();
-
-        expect(mockBackend.execute(
-            eq(route),
-            isA(HttpRequestWrapper.class),
-            isA(HttpClientContext.class),
-            (HttpExecutionAware) isNull())).andThrow(
-                new AssertionFailedError("Should have reused cached 304 response")).anyTimes();
+        expect(
+            mockBackend.execute(eq(route), isA(HttpRequestWrapper.class),
+                isA(HttpClientContext.class), (HttpExecutionAware) isNull())).andReturn(
+            Proxies.enhanceResponse(resp1)).once();
+
+        expect(
+            mockBackend.execute(eq(route), isA(HttpRequestWrapper.class),
+                isA(HttpClientContext.class), (HttpExecutionAware) isNull())).andThrow(
+            new AssertionFailedError("Should have reused cached 304 response")).anyTimes();
 
         replayMocks();
         impl.execute(route, req1, context, null);
@@ -611,11 +607,13 @@ public abstract class TestCachingExecCha
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -624,8 +622,7 @@ public abstract class TestCachingExecCha
         resp1.setHeader("Last-Modified", DateUtils.formatDate(new Date()));
 
         // The variant has been modified since this date
-        req2.addHeader("If-Modified-Since", DateUtils
-                        .formatDate(tenSecondsAgo));
+        req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
 
         final HttpResponse resp2 = HttpTestUtils.make200Response();
 
@@ -641,16 +638,17 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns200ForIfModifiedSinceDateIsInvalid()
-            throws Exception {
+    public void testReturns200ForIfModifiedSinceDateIsInvalid() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAfter = new Date(now.getTime() + 10 * 1000L);
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -659,8 +657,7 @@ public abstract class TestCachingExecCha
         resp1.setHeader("Last-Modified", DateUtils.formatDate(new Date()));
 
         // invalid date (date in the future)
-        req2.addHeader("If-Modified-Since", DateUtils
-                .formatDate(tenSecondsAfter));
+        req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAfter));
 
         backendExpectsAnyRequestAndReturn(resp1).times(2);
 
@@ -673,14 +670,15 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns304ForIfNoneMatchHeaderIfRequestServedFromCache()
-            throws Exception {
+    public void testReturns304ForIfNoneMatchHeaderIfRequestServedFromCache() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.addHeader("If-None-Match", "*");
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -700,11 +698,13 @@ public abstract class TestCachingExecCha
     @Test
     public void testReturns200ForIfNoneMatchHeaderFails() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -728,15 +728,17 @@ public abstract class TestCachingExecCha
 
     @Test
     public void testReturns304ForIfNoneMatchHeaderAndIfModifiedSinceIfRequestServedFromCache()
-            throws Exception {
+        throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -758,17 +760,18 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns200ForIfNoneMatchHeaderFailsIfModifiedSinceIgnored()
-            throws Exception {
+    public void testReturns200ForIfNoneMatchHeaderFailsIfModifiedSinceIgnored() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.addHeader("If-None-Match", "\"abc\"");
         req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -789,22 +792,25 @@ public abstract class TestCachingExecCha
 
     @Test
     public void testReturns200ForOptionsFollowedByGetIfAuthorizationHeaderAndSharedCache()
-            throws Exception {
-        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.custom().setSharedCache(true).build());
+        throws Exception {
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.custom()
+            .setSharedCache(true).build());
         final Date now = new Date();
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpOptions("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpOptions(
+            "http://foo.example.com/"));
         req1.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
         final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_NO_CONTENT, "No Content");
+            HttpStatus.SC_NO_CONTENT, "No Content");
         resp1.setHeader("Content-Length", "0");
         resp1.setHeader("ETag", "\"options-etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(now));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
         resp1.setHeader("Last-Modified", DateUtils.formatDate(now));
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"get-etag\"");
@@ -823,28 +829,31 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testSetsValidatedContextIfRequestWasSuccessfullyValidated()
-        throws Exception {
+    public void testSetsValidatedContextIfRequestWasSuccessfullyValidated() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Cache-Control","public, max-age=5");
+        resp1.setHeader("Cache-Control", "public, max-age=5");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
-        resp2.setHeader("Content-Length","128");
-        resp2.setHeader("ETag","\"etag\"");
+        resp2.setHeader("Content-Length", "128");
+        resp2.setHeader("ETag", "\"etag\"");
         resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp2.setHeader("Cache-Control","public, max-age=5");
+        resp2.setHeader("Cache-Control", "public, max-age=5");
 
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndReturn(resp2);
@@ -853,33 +862,35 @@ public abstract class TestCachingExecCha
         impl.execute(route, req1, context, null);
         impl.execute(route, req2, context, null);
         verifyMocks();
-        Assert.assertEquals(CacheResponseStatus.VALIDATED,
-                context.getCacheResponseStatus());
+        Assert.assertEquals(CacheResponseStatus.VALIDATED, context.getCacheResponseStatus());
     }
 
     @Test
-    public void testSetsViaHeaderIfRequestWasSuccessfullyValidated()
-        throws Exception {
+    public void testSetsViaHeaderIfRequestWasSuccessfullyValidated() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Cache-Control","public, max-age=5");
+        resp1.setHeader("Cache-Control", "public, max-age=5");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
-        resp2.setHeader("Content-Length","128");
-        resp2.setHeader("ETag","\"etag\"");
+        resp2.setHeader("Content-Length", "128");
+        resp2.setHeader("ETag", "\"etag\"");
         resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp2.setHeader("Cache-Control","public, max-age=5");
+        resp2.setHeader("Cache-Control", "public, max-age=5");
 
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndReturn(resp2);
@@ -891,23 +902,24 @@ public abstract class TestCachingExecCha
         Assert.assertNotNull(result.getFirstHeader("Via"));
     }
 
-
     @Test
-    public void testSetsModuleResponseContextIfValidationRequiredButFailed()
-        throws Exception {
+    public void testSetsModuleResponseContextIfValidationRequiredButFailed() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Cache-Control","public, max-age=5, must-revalidate");
+        resp1.setHeader("Cache-Control", "public, max-age=5, must-revalidate");
 
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndThrows(new IOException());
@@ -917,25 +929,27 @@ public abstract class TestCachingExecCha
         impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE,
-                context.getCacheResponseStatus());
+            context.getCacheResponseStatus());
     }
 
     @Test
-    public void testSetsModuleResponseContextIfValidationFailsButNotRequired()
-        throws Exception {
+    public void testSetsModuleResponseContextIfValidationFailsButNotRequired() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Cache-Control","public, max-age=5");
+        resp1.setHeader("Cache-Control", "public, max-age=5");
 
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndThrows(new IOException());
@@ -944,26 +958,27 @@ public abstract class TestCachingExecCha
         impl.execute(route, req1, context, null);
         impl.execute(route, req2, context, null);
         verifyMocks();
-        Assert.assertEquals(CacheResponseStatus.CACHE_HIT,
-                context.getCacheResponseStatus());
+        Assert.assertEquals(CacheResponseStatus.CACHE_HIT, context.getCacheResponseStatus());
     }
 
     @Test
-    public void testSetViaHeaderIfValidationFailsButNotRequired()
-        throws Exception {
+    public void testSetViaHeaderIfValidationFailsButNotRequired() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
-        resp1.setHeader("Content-Length","128");
-        resp1.setHeader("ETag","\"etag\"");
+        resp1.setHeader("Content-Length", "128");
+        resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Cache-Control","public, max-age=5");
+        resp1.setHeader("Cache-Control", "public, max-age=5");
 
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndThrows(new IOException());
@@ -976,18 +991,19 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns304ForIfNoneMatchPassesIfRequestServedFromOrigin()
-            throws Exception {
+    public void testReturns304ForIfNoneMatchPassesIfRequestServedFromOrigin() throws Exception {
 
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -996,7 +1012,7 @@ public abstract class TestCachingExecCha
 
         req2.addHeader("If-None-Match", "\"etag\"");
         final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_NOT_MODIFIED, "Not Modified");
+            HttpStatus.SC_NOT_MODIFIED, "Not Modified");
         resp2.setHeader("ETag", "\"etag\"");
         resp2.setHeader("Date", DateUtils.formatDate(now));
         resp2.setHeader("Cache-Control", "public, max-age=5");
@@ -1012,18 +1028,19 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns200ForIfNoneMatchFailsIfRequestServedFromOrigin()
-            throws Exception {
+    public void testReturns200ForIfNoneMatchFailsIfRequestServedFromOrigin() throws Exception {
 
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -1031,8 +1048,8 @@ public abstract class TestCachingExecCha
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         req2.addHeader("If-None-Match", "\"etag\"");
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("ETag", "\"newetag\"");
@@ -1051,18 +1068,19 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns304ForIfModifiedSincePassesIfRequestServedFromOrigin()
-            throws Exception {
+    public void testReturns304ForIfModifiedSincePassesIfRequestServedFromOrigin() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -1072,7 +1090,7 @@ public abstract class TestCachingExecCha
 
         req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
         final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_NOT_MODIFIED, "Not Modified");
+            HttpStatus.SC_NOT_MODIFIED, "Not Modified");
         resp2.setHeader("ETag", "\"etag\"");
         resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
         resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
@@ -1090,17 +1108,18 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testReturns200ForIfModifiedSinceFailsIfRequestServedFromOrigin()
-            throws Exception {
+    public void testReturns200ForIfModifiedSinceFailsIfRequestServedFromOrigin() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
@@ -1109,8 +1128,8 @@ public abstract class TestCachingExecCha
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("ETag", "\"newetag\"");
@@ -1134,10 +1153,12 @@ public abstract class TestCachingExecCha
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req1.addHeader("Accept-Encoding", "gzip");
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("Etag", "\"gzip_etag\"");
@@ -1145,14 +1166,17 @@ public abstract class TestCachingExecCha
         resp1.setHeader("Vary", "Accept-Encoding");
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req2.addHeader("Accept-Encoding", "deflate");
 
-        final HttpRequestWrapper req2Server = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req2Server = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req2Server.addHeader("Accept-Encoding", "deflate");
         req2Server.addHeader("If-None-Match", "\"gzip_etag\"");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("Etag", "\"deflate_etag\"");
@@ -1160,14 +1184,17 @@ public abstract class TestCachingExecCha
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setHeader("Cache-Control", "public, max-age=3600");
 
-        final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req3.addHeader("Accept-Encoding", "gzip,deflate");
 
-        final HttpRequestWrapper req3Server = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req3Server = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req3Server.addHeader("Accept-Encoding", "gzip,deflate");
         req3Server.addHeader("If-None-Match", "\"gzip_etag\",\"deflate_etag\"");
 
-        final HttpResponse resp3 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp3 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Content-Length", "128");
         resp3.setHeader("Etag", "\"gzip_etag\"");
@@ -1197,10 +1224,12 @@ public abstract class TestCachingExecCha
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req1.addHeader("Accept-Encoding", "gzip");
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("Etag", "\"gzip_etag\"");
@@ -1208,14 +1237,17 @@ public abstract class TestCachingExecCha
         resp1.setHeader("Vary", "Accept-Encoding");
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req2.addHeader("Accept-Encoding", "deflate");
 
-        final HttpRequestWrapper req2Server = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req2Server = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req2Server.addHeader("Accept-Encoding", "deflate");
         req2Server.addHeader("If-None-Match", "\"gzip_etag\"");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("Etag", "\"deflate_etag\"");
@@ -1223,15 +1255,18 @@ public abstract class TestCachingExecCha
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setHeader("Cache-Control", "public, max-age=3600");
 
-        final HttpRequestWrapper req4 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req4 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req4.addHeader("Accept-Encoding", "gzip,identity");
         req4.addHeader("If-None-Match", "\"gzip_etag\"");
 
-        final HttpRequestWrapper req4Server = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
+        final HttpRequestWrapper req4Server = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com"));
         req4Server.addHeader("Accept-Encoding", "gzip,identity");
         req4Server.addHeader("If-None-Match", "\"gzip_etag\"");
 
-        final HttpResponse resp4 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified");
+        final HttpResponse resp4 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not Modified");
         resp4.setHeader("Etag", "\"gzip_etag\"");
         resp4.setHeader("Date", DateUtils.formatDate(now));
         resp4.setHeader("Vary", "Accept-Encoding");
@@ -1255,16 +1290,15 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testSocketTimeoutExceptionIsNotSilentlyCatched()
-            throws Exception {
+    public void testSocketTimeoutExceptionIsNotSilentlyCatched() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
-                "http://foo.example.com"));
+            "http://foo.example.com"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "OK");
         resp1.setEntity(new InputStreamEntity(new InputStream() {
             private boolean closed = false;
 
@@ -1302,31 +1336,27 @@ public abstract class TestCachingExecCha
     }
 
     @Test
-    public void testTreatsCacheIOExceptionsAsCacheMiss()
-        throws Exception {
+    public void testTreatsCacheIOExceptionsAsCacheMiss() throws Exception {
 
         impl = createCachingExecChain(mockBackend, mockCache, CacheConfig.DEFAULT);
         final CloseableHttpResponse resp = Proxies.enhanceResponse(HttpTestUtils.make200Response());
 
         mockCache.flushInvalidatedCacheEntriesFor(host, request);
         expectLastCall().andThrow(new IOException()).anyTimes();
-        mockCache.flushInvalidatedCacheEntriesFor(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpResponse.class));
+        mockCache.flushInvalidatedCacheEntriesFor(isA(HttpHost.class), isA(HttpRequest.class),
+            isA(HttpResponse.class));
         expectLastCall().anyTimes();
-        expect(mockCache.getCacheEntry(eq(host),
-                isA(HttpRequest.class)))
+        expect(mockCache.getCacheEntry(eq(host), isA(HttpRequest.class))).andThrow(
+            new IOException()).anyTimes();
+        expect(mockCache.getVariantCacheEntriesWithEtags(eq(host), isA(HttpRequest.class)))
             .andThrow(new IOException()).anyTimes();
-        expect(mockCache.getVariantCacheEntriesWithEtags(eq(host),
-                isA(HttpRequest.class)))
-            .andThrow(new IOException()).anyTimes();
-        expect(mockCache.cacheAndReturnResponse(eq(host),
-                isA(HttpRequest.class), isA(CloseableHttpResponse.class),
-                isA(Date.class), isA(Date.class)))
+        expect(
+            mockCache.cacheAndReturnResponse(eq(host), isA(HttpRequest.class),
+                isA(CloseableHttpResponse.class), isA(Date.class), isA(Date.class)))
             .andReturn(resp).anyTimes();
-        expect(mockBackend.execute(
-                eq(route),
-                isA(HttpRequestWrapper.class),
-                isA(HttpClientContext.class),
-                (HttpExecutionAware) isNull())).andReturn(resp);
+        expect(
+            mockBackend.execute(eq(route), isA(HttpRequestWrapper.class),
+                isA(HttpClientContext.class), (HttpExecutionAware) isNull())).andReturn(resp);
 
         replayMocks();
         final HttpResponse result = impl.execute(route, request, context, null);
@@ -1350,7 +1380,8 @@ public abstract class TestCachingExecCha
 
         request.setHeader("Cache-Control", "only-if-cached");
 
-        entry = HttpTestUtils.makeCacheEntry(new Header[]{new BasicHeader("Cache-Control", "must-revalidate")});
+        entry = HttpTestUtils.makeCacheEntry(new Header[] { new BasicHeader("Cache-Control",
+            "must-revalidate") });
 
         requestIsFatallyNonCompliant(null);
         cacheInvalidatorWasCalled();
@@ -1393,6 +1424,7 @@ public abstract class TestCachingExecCha
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
+        ctx.setTargetHost(host);
         impl.execute(route, request, context, null);
         impl.execute(route, request, ctx, null);
         assertNull(ctx.getConnection());
@@ -1406,6 +1438,7 @@ public abstract class TestCachingExecCha
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
+        ctx.setTargetHost(host);
         impl.execute(route, request, context, null);
         impl.execute(route, request, ctx, null);
         assertSame(host, ctx.getTargetHost());
@@ -1419,6 +1452,7 @@ public abstract class TestCachingExecCha
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
+        ctx.setTargetHost(host);
         impl.execute(route, request, context, null);
         impl.execute(route, request, ctx, null);
         assertEquals(route, ctx.getHttpRoute());
@@ -1432,6 +1466,7 @@ public abstract class TestCachingExecCha
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
+        ctx.setTargetHost(host);
         impl.execute(route, request, context, null);
         impl.execute(route, request, ctx, null);
         if (!HttpTestUtils.equivalent(request, ctx.getRequest())) {
@@ -1447,6 +1482,7 @@ public abstract class TestCachingExecCha
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
+        ctx.setTargetHost(host);
         impl.execute(route, request, context, null);
         final HttpResponse result = impl.execute(route, request, ctx, null);
         if (!HttpTestUtils.equivalent(result, ctx.getResponse())) {
@@ -1462,6 +1498,7 @@ public abstract class TestCachingExecCha
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
+        ctx.setTargetHost(host);
         impl.execute(route, request, context, null);
         impl.execute(route, request, ctx, null);
         assertTrue(ctx.isRequestSent());
@@ -1469,9 +1506,10 @@ public abstract class TestCachingExecCha
 
     @Test
     public void testCanCacheAResponseWithoutABody() throws Exception {
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content");
+        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NO_CONTENT, "No Content");
         response.setHeader("Date", DateUtils.formatDate(new Date()));
-        response.setHeader("Cache-Control","max-age=300");
+        response.setHeader("Cache-Control", "max-age=300");
         final DummyBackend backend = new DummyBackend();
         backend.setResponse(response);
         impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
@@ -1488,11 +1526,11 @@ public abstract class TestCachingExecCha
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
-                "http://foo.example.com/"));
+            "http://foo.example.com/"));
         req1.addHeader("If-None-Match", "\"etag\"");
 
         final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_NOT_MODIFIED, "Not modified");
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
@@ -1503,10 +1541,8 @@ public abstract class TestCachingExecCha
         final HttpResponse result = impl.execute(route, req1, context, null);
         verifyMocks();
 
-        assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine()
-                .getStatusCode());
-        assertNull("The 304 response messages MUST NOT contain a message-body",
-                result.getEntity());
+        assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
+        assertNull("The 304 response messages MUST NOT contain a message-body", result.getEntity());
     }
 
     @Test
@@ -1516,20 +1552,24 @@ public abstract class TestCachingExecCha
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req1.addHeader("If-None-Match", "etag");
 
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.addHeader("If-None-Match", "etag");
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp1.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Cache-Control","max-age=0");
+        resp1.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp2.setHeader("Date", DateUtils.formatDate(now));
-        resp2.setHeader("Cache-Control","max-age=0");
+        resp2.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
 
         backendExpectsAnyRequestAndReturn(resp1);
@@ -1552,21 +1592,25 @@ public abstract class TestCachingExecCha
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req1.addHeader("If-None-Match", "etag");
 
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req2.addHeader("If-None-Match", "etag");
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp1.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Cache-Control","max-age=0");
+        resp1.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
         resp1.setHeader("Vary", "Accept-Encoding");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp2.setHeader("Date", DateUtils.formatDate(now));
-        resp2.setHeader("Cache-Control","max-age=0");
+        resp2.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
         resp1.setHeader("Vary", "Accept-Encoding");
 
@@ -1587,26 +1631,30 @@ public abstract class TestCachingExecCha
     public void testDoesNotSend304ForNonConditionalRequest() throws Exception {
 
         final Date now = new Date();
-        final Date inOneMinute = new Date(System.currentTimeMillis()+60000);
+        final Date inOneMinute = new Date(System.currentTimeMillis() + 60000);
 
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
-        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
         req1.addHeader("If-None-Match", "etag");
 
-        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
+        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
+            "http://foo.example.com/"));
 
-        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
+        final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
+            HttpStatus.SC_NOT_MODIFIED, "Not modified");
         resp1.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Cache-Control","public, max-age=60");
-        resp1.setHeader("Expires",DateUtils.formatDate(inOneMinute));
+        resp1.setHeader("Cache-Control", "public, max-age=60");
+        resp1.setHeader("Expires", DateUtils.formatDate(inOneMinute));
         resp1.setHeader("Etag", "etag");
         resp1.setHeader("Vary", "Accept-Encoding");
 
-        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "Ok");
+        final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
+            "Ok");
         resp2.setHeader("Date", DateUtils.formatDate(now));
-        resp2.setHeader("Cache-Control","public, max-age=60");
-        resp2.setHeader("Expires",DateUtils.formatDate(inOneMinute));
+        resp2.setHeader("Cache-Control", "public, max-age=60");
+        resp2.setHeader("Expires", DateUtils.formatDate(inOneMinute));
         resp2.setHeader("Etag", "etag");
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setEntity(HttpTestUtils.makeBody(128));
@@ -1624,53 +1672,59 @@ public abstract class TestCachingExecCha
         Assert.assertNotNull(result2.getEntity());
     }
 
+    @Test
+    public void testUsesVirtualHostForCacheKey() throws Exception {
+        final DummyBackend backend = new DummyBackend();
+        final HttpResponse response = HttpTestUtils.make200Response();
+        response.setHeader("Cache-Control", "max-age=3600");
+        backend.setResponse(response);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl.execute(route, request, context, null);
+        assertEquals(1, backend.getExecutions());
+        context.setTargetHost(new HttpHost("bar.example.com"));
+        impl.execute(route, request, context, null);
+        assertEquals(2, backend.getExecutions());
+        impl.execute(route, request, context, null);
+        assertEquals(2, backend.getExecutions());
+    }
+
     private IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndReturn(
-            final HttpResponse response) throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.isA(HttpRequestWrapper.class),
-                EasyMock.isA(HttpClientContext.class),
-                EasyMock.<HttpExecutionAware>isNull());
+        final HttpResponse response) throws Exception {
+        final CloseableHttpResponse resp = mockBackend.execute(EasyMock.isA(HttpRoute.class),
+            EasyMock.isA(HttpRequestWrapper.class), EasyMock.isA(HttpClientContext.class),
+            EasyMock.<HttpExecutionAware> isNull());
         return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
     }
 
     protected IExpectationSetters<CloseableHttpResponse> backendExpectsRequestAndReturn(
-            final HttpRequestWrapper request, final HttpResponse response) throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.eq(request),
-                EasyMock.isA(HttpClientContext.class),
-                EasyMock.<HttpExecutionAware>isNull());
+        final HttpRequestWrapper request, final HttpResponse response) throws Exception {
+        final CloseableHttpResponse resp = mockBackend.execute(EasyMock.isA(HttpRoute.class),
+            EasyMock.eq(request), EasyMock.isA(HttpClientContext.class),
+            EasyMock.<HttpExecutionAware> isNull());
         return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
     }
 
     protected IExpectationSetters<CloseableHttpResponse> backendExpectsRequestAndReturn(
-            final HttpRequestWrapper request, final CloseableHttpResponse response) throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.eq(request),
-                EasyMock.isA(HttpClientContext.class),
-                EasyMock.<HttpExecutionAware>isNull());
+        final HttpRequestWrapper request, final CloseableHttpResponse response) throws Exception {
+        final CloseableHttpResponse resp = mockBackend.execute(EasyMock.isA(HttpRoute.class),
+            EasyMock.eq(request), EasyMock.isA(HttpClientContext.class),
+            EasyMock.<HttpExecutionAware> isNull());
         return EasyMock.expect(resp).andReturn(response);
     }
 
     protected IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndThrows(
-            final Throwable throwable) throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.isA(HttpRequestWrapper.class),
-                EasyMock.isA(HttpClientContext.class),
-                EasyMock.<HttpExecutionAware>isNull());
+        final Throwable throwable) throws Exception {
+        final CloseableHttpResponse resp = mockBackend.execute(EasyMock.isA(HttpRoute.class),
+            EasyMock.isA(HttpRequestWrapper.class), EasyMock.isA(HttpClientContext.class),
+            EasyMock.<HttpExecutionAware> isNull());
         return EasyMock.expect(resp).andThrow(throwable);
     }
 
     protected IExpectationSetters<CloseableHttpResponse> backendCaptureRequestAndReturn(
-            final Capture<HttpRequestWrapper> cap, final HttpResponse response) throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.capture(cap),
-                EasyMock.isA(HttpClientContext.class),
-                EasyMock.<HttpExecutionAware>isNull());
+        final Capture<HttpRequestWrapper> cap, final HttpResponse response) throws Exception {
+        final CloseableHttpResponse resp = mockBackend.execute(EasyMock.isA(HttpRoute.class),
+            EasyMock.capture(cap), EasyMock.isA(HttpClientContext.class),
+            EasyMock.<HttpExecutionAware> isNull());
         return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
     }
 
@@ -1678,62 +1732,56 @@ public abstract class TestCachingExecCha
         expect(mockCache.getCacheEntry(eq(host), eqRequest(request))).andReturn(result);
     }
 
-    private void cacheInvalidatorWasCalled()  throws IOException {
-        mockCache.flushInvalidatedCacheEntriesFor(
-                (HttpHost)anyObject(),
-                (HttpRequest)anyObject());
+    private void cacheInvalidatorWasCalled() throws IOException {
+        mockCache
+            .flushInvalidatedCacheEntriesFor((HttpHost) anyObject(), (HttpRequest) anyObject());
     }
 
     protected void cacheEntryValidatable(final boolean b) {
-        expect(mockValidityPolicy.isRevalidatable(
-                (HttpCacheEntry)anyObject())).andReturn(b).anyTimes();
+        expect(mockValidityPolicy.isRevalidatable((HttpCacheEntry) anyObject())).andReturn(b)
+            .anyTimes();
     }
 
     protected void cacheEntryMustRevalidate(final boolean b) {
-        expect(mockValidityPolicy.mustRevalidate(mockCacheEntry))
-            .andReturn(b);
+        expect(mockValidityPolicy.mustRevalidate(mockCacheEntry)).andReturn(b);
     }
 
     protected void cacheEntryProxyRevalidate(final boolean b) {
-        expect(mockValidityPolicy.proxyRevalidate(mockCacheEntry))
-            .andReturn(b);
+        expect(mockValidityPolicy.proxyRevalidate(mockCacheEntry)).andReturn(b);
     }
 
     protected void mayReturnStaleWhileRevalidating(final boolean b) {
-        expect(mockValidityPolicy.mayReturnStaleWhileRevalidating(
-                (HttpCacheEntry)anyObject(), (Date)anyObject())).andReturn(b);
+        expect(
+            mockValidityPolicy.mayReturnStaleWhileRevalidating((HttpCacheEntry) anyObject(),
+                (Date) anyObject())).andReturn(b);
     }
 
     protected void conditionalRequestBuilderReturns(final HttpRequestWrapper validate)
-            throws Exception {
-        expect(mockConditionalRequestBuilder.buildConditionalRequest(
-                request, entry)).andReturn(validate);
+        throws Exception {
+        expect(mockConditionalRequestBuilder.buildConditionalRequest(request, entry)).andReturn(
+            validate);
     }
 
     protected void requestPolicyAllowsCaching(final boolean allow) {
-        expect(mockRequestPolicy.isServableFromCache(
-                (HttpRequest)anyObject())).andReturn(allow);
+        expect(mockRequestPolicy.isServableFromCache((HttpRequest) anyObject())).andReturn(allow);
     }
 
     protected void cacheEntrySuitable(final boolean suitable) {
         expect(
-                mockSuitabilityChecker.canCachedResponseBeUsed(
-                        (HttpHost)anyObject(),
-                        (HttpRequest)anyObject(),
-                        (HttpCacheEntry)anyObject(),
-                        (Date)anyObject())).andReturn(suitable);
+            mockSuitabilityChecker.canCachedResponseBeUsed((HttpHost) anyObject(),
+                (HttpRequest) anyObject(), (HttpCacheEntry) anyObject(), (Date) anyObject()))
+            .andReturn(suitable);
     }
 
     private void entryHasStaleness(final long staleness) {
-        expect(mockValidityPolicy.getStalenessSecs(
-                (HttpCacheEntry)anyObject(),
-                (Date)anyObject()
-                )).andReturn(staleness);
+        expect(
+            mockValidityPolicy.getStalenessSecs((HttpCacheEntry) anyObject(), (Date) anyObject()))
+            .andReturn(staleness);
     }
 
     protected void responseIsGeneratedFromCache() {
-        expect(mockResponseGenerator.generateResponse(
-                (HttpCacheEntry)anyObject())).andReturn(mockCachedResponse);
+        expect(mockResponseGenerator.generateResponse((HttpCacheEntry) anyObject())).andReturn(
+            mockCachedResponse);
     }
 
 }



Mime
View raw message