hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1618558 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/CachingExec.java test/java/org/apache/http/impl/client/cache/TestCachingExec.java
Date Mon, 18 Aug 2014 07:55:10 GMT
Author: olegk
Date: Mon Aug 18 07:55:10 2014
New Revision: 1618558

URL: http://svn.apache.org/r1618558
Log:
HTTPCLIENT-1542: Caching HttpClient uses absolute URIs for validation (follow-up patch, more
tests)
Based on contribution by Joseph Walton <joe at kafsemo.org>

Modified:
    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/TestCachingExec.java

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=1618558&r1=1618557&r2=1618558&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
Mon Aug 18 07:55:10 2014
@@ -745,7 +745,7 @@ public class CachingExec implements Clie
         final URI uri = conditionalRequest.getURI();
         if (uri != null) {
             try {
-                request.setURI(URIUtils.rewriteURIForRoute(uri, route));
+                conditionalRequest.setURI(URIUtils.rewriteURIForRoute(uri, route));
             } catch (final URISyntaxException ex) {
                 throw new ProtocolException("Invalid URI: " + uri, ex);
             }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java?rev=1618558&r1=1618557&r2=1618558&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
Mon Aug 18 07:55:10 2014
@@ -53,6 +53,7 @@ import org.apache.http.HttpVersion;
 import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpExecutionAware;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.utils.DateUtils;
@@ -309,6 +310,36 @@ public class TestCachingExec extends Tes
     }
 
     @Test
+    public void testRevalidationRewritesAbsoluteUri() throws Exception {
+
+        mockImplMethods(GET_CURRENT_DATE);
+
+        // Fail on an unexpected request, rather than causing a later NPE
+        EasyMock.resetToStrict(mockBackend);
+
+        final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
+                new HttpGet("http://foo.example.com/resource"));
+        final HttpRequestWrapper relativeValidate = HttpRequestWrapper.wrap(
+                new BasicHttpRequest("GET", "/resource", HttpVersion.HTTP_1_1));
+        final CloseableHttpResponse originResponse = Proxies.enhanceResponse(
+            new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "Okay"));
+
+        conditionalRequestBuilderReturns(validate);
+        getCurrentDateReturns(requestDate);
+
+        final CloseableHttpResponse resp = mockBackend.execute(EasyMock.isA(HttpRoute.class),
+                eqRequest(relativeValidate), EasyMock.isA(HttpClientContext.class),
+                EasyMock.<HttpExecutionAware> isNull());
+        expect(resp).andReturn(originResponse);
+
+        getCurrentDateReturns(responseDate);
+
+        replayMocks();
+        impl.revalidateCacheEntry(route, request, context, null, entry);
+        verifyMocks();
+    }
+
+    @Test
     public void testEndlessResponsesArePassedThrough() throws Exception {
         impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 



Mime
View raw message