hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1044824 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Sun, 12 Dec 2010 14:24:25 GMT
Author: jonm
Date: Sun Dec 12 14:24:25 2010
New Revision: 1044824

URL: http://svn.apache.org/viewvc?rev=1044824&view=rev
Log:
HTTPCLIENT-1032: minor refactoring on URIExtractor to clean up
internal-only API for getVariantKey()

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java?rev=1044824&r1=1044823&r2=1044824&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
Sun Dec 12 14:24:25 2010
@@ -235,22 +235,16 @@ class BasicHttpCache implements HttpCach
     public void flushInvalidatedCacheEntriesFor(HttpHost host,
             HttpRequest request) throws IOException {
         cacheInvalidator.flushInvalidatedCacheEntries(host, request);
-
     }
 
     public Set<HttpCacheEntry> getVariantCacheEntries(HttpHost host, HttpRequest request)
             throws IOException {
         Set<HttpCacheEntry> variants = new HashSet<HttpCacheEntry>();
-
         HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
-        if (root != null) {
-            if (root.hasVariants()) {
-                for(String variantUri : root.getVariantMap().values()) {
-                    variants.add(storage.getEntry(variantUri));
-                }
-            }
+        if (root == null || !root.hasVariants()) return variants;
+        for(String variantCacheKey : root.getVariantMap().values()) {
+            variants.add(storage.getEntry(variantCacheKey));
         }
-
         return variants;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java?rev=1044824&r1=1044823&r2=1044824&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java
Sun Dec 12 14:24:25 2010
@@ -136,16 +136,22 @@ class URIExtractor {
      * @return String the extracted variant URI
      */
     public String getVariantURI(HttpHost host, HttpRequest req, HttpCacheEntry entry) {
-        Header[] varyHdrs = entry.getHeaders(HeaderConstants.VARY);
-        if (varyHdrs == null || varyHdrs.length == 0) {
-            return getURI(host, req);
-        }
-        return getVariantKey(req, varyHdrs) + getURI(host, req);
+        if (!entry.hasVariants()) return getURI(host, req);
+        return getVariantKey(req, entry) + getURI(host, req);
     }
 
-    public String getVariantKey(HttpRequest req, Header[] varyHdrs) {
+    /**
+     * Compute a "variant key" from the headers of a given request that are
+     * covered by the Vary header of a given cache entry. Any request whose
+     * varying headers match those of this request should have the same
+     * variant key. 
+     * @param req originating request
+     * @param entry cache entry in question that has variants
+     * @return a <code>String</code> variant key
+     */
+    public String getVariantKey(HttpRequest req, HttpCacheEntry entry) {
         List<String> variantHeaderNames = new ArrayList<String>();
-        for (Header varyHdr : varyHdrs) {
+        for (Header varyHdr : entry.getHeaders(HeaderConstants.VARY)) {
             for (HeaderElement elt : varyHdr.getElements()) {
                 variantHeaderNames.add(elt.getName());
             }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java?rev=1044824&r1=1044823&r2=1044824&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java
Sun Dec 12 14:24:25 2010
@@ -123,8 +123,7 @@ public class TestURIExtractor {
     @Test
     public void testGetVariantURIWithNoVaryHeaderReturnsNormalURI() {
         final String theURI = "theURI";
-        Header[] noHdrs = new Header[0];
-        org.easymock.EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(noHdrs);
+        org.easymock.EasyMock.expect(mockEntry.hasVariants()).andReturn(false);
         extractor = new URIExtractor() {
             @Override
             public String getURI(HttpHost h, HttpRequest req) {
@@ -154,8 +153,9 @@ public class TestURIExtractor {
                 return theURI;
             }
         };
-        org.easymock.EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
-        org.easymock.EasyMock.expect(mockRequest.getHeaders("Accept-Encoding")).andReturn(
+        EasyMock.expect(mockEntry.hasVariants()).andReturn(true).anyTimes();
+        EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
+        EasyMock.expect(mockRequest.getHeaders("Accept-Encoding")).andReturn(
                 encHeaders);
         replayMocks();
 
@@ -178,8 +178,9 @@ public class TestURIExtractor {
                 return theURI;
             }
         };
-        org.easymock.EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
-        org.easymock.EasyMock.expect(mockRequest.getHeaders("Accept-Encoding"))
+        EasyMock.expect(mockEntry.hasVariants()).andReturn(true).anyTimes();
+        EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
+        EasyMock.expect(mockRequest.getHeaders("Accept-Encoding"))
                 .andReturn(noHeaders);
         replayMocks();
 
@@ -203,10 +204,11 @@ public class TestURIExtractor {
                 return theURI;
             }
         };
-        org.easymock.EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
-        org.easymock.EasyMock.expect(mockRequest.getHeaders("Accept-Encoding")).andReturn(
+        EasyMock.expect(mockEntry.hasVariants()).andReturn(true).anyTimes();
+        EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
+        EasyMock.expect(mockRequest.getHeaders("Accept-Encoding")).andReturn(
                 encHeaders);
-        org.easymock.EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
+        EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
         replayMocks();
 
         String result = extractor.getVariantURI(host, mockRequest, mockEntry);
@@ -230,6 +232,7 @@ public class TestURIExtractor {
                 return theURI;
             }
         };
+        EasyMock.expect(mockEntry.hasVariants()).andReturn(true).anyTimes();
         EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
         EasyMock.expect(mockRequest.getHeaders("Accept-Encoding")).andReturn(encHeaders);
         EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
@@ -256,6 +259,7 @@ public class TestURIExtractor {
                 return theURI;
             }
         };
+        EasyMock.expect(mockEntry.hasVariants()).andReturn(true).anyTimes();
         EasyMock.expect(mockEntry.getHeaders("Vary")).andReturn(varyHeaders);
         EasyMock.expect(mockRequest.getHeaders("Accept-Encoding")).andReturn(encHeaders);
         EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);



Mime
View raw message