You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by jo...@apache.org on 2010/12/08 23:04:48 UTC

svn commit: r1043717 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/CachingHttpClient.java test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java

Author: jonm
Date: Wed Dec  8 22:04:48 2010
New Revision: 1043717

URL: http://svn.apache.org/viewvc?rev=1043717&view=rev
Log:
Cache revalidation of entries now sends etags of all cached variants on
the conditional request. (Commit of my own patch posted to
https://issues.apache.org/jira/browse/HTTPCLIENT-1024 before I had
commit rights).

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=1043717&r1=1043716&r2=1043717&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java Wed Dec  8 22:04:48 2010
@@ -414,7 +414,7 @@ public class CachingHttpClient implement
 
             Set<HttpCacheEntry> variantEntries = null;
             try {
-                responseCache.getVariantCacheEntries(target, request);
+                variantEntries = responseCache.getVariantCacheEntries(target, request);
             } catch (IOException ioe) {
                 log.warn("Unable to retrieve variant entries from cache", ioe);
             }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java?rev=1043717&r1=1043716&r2=1043717&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java Wed Dec  8 22:04:48 2010
@@ -806,4 +806,63 @@ public class TestProtocolRecommendations
         assertNull(captured.getFirstHeader("If-Match"));
         assertNull(captured.getFirstHeader("If-Unmodified-Since"));
     }
+    
+    /* "If an entity tag was assigned to a cached representation, the
+     * forwarded request SHOULD be conditional and include the entity
+     * tags in an If-None-Match header field from all its cache entries
+     * for the resource."
+     * 
+     * http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.6
+     */
+    @Test
+    public void testSendsAllVariantEtagsInConditionalRequest()
+    	throws Exception {
+    	HttpRequest req1 = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
+    	req1.setHeader("User-Agent","agent1");
+    	HttpResponse resp1 = HttpTestUtils.make200Response();
+    	resp1.setHeader("Cache-Control","max-age=3600");
+    	resp1.setHeader("Vary","User-Agent");
+    	resp1.setHeader("Etag","\"etag1\"");
+    	
+    	backendExpectsAnyRequest().andReturn(resp1);
+
+    	HttpRequest req2 = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
+    	req2.setHeader("User-Agent","agent2");
+    	HttpResponse resp2 = HttpTestUtils.make200Response();
+    	resp2.setHeader("Cache-Control","max-age=3600");
+    	resp2.setHeader("Vary","User-Agent");
+    	resp2.setHeader("Etag","\"etag2\"");
+
+    	backendExpectsAnyRequest().andReturn(resp2);
+    	
+    	Capture<HttpRequest> cap = new Capture<HttpRequest>();
+    	HttpRequest req3 = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
+    	req3.setHeader("User-Agent","agent3");
+    	HttpResponse resp3 = HttpTestUtils.make200Response();
+    	
+    	EasyMock.expect(mockBackend.execute(EasyMock.eq(host),
+    			EasyMock.capture(cap), (HttpContext)EasyMock.isNull()))
+    		.andReturn(resp3);
+    	
+    	replayMocks();
+    	impl.execute(host,req1);
+    	impl.execute(host,req2);
+    	impl.execute(host,req3);
+    	verifyMocks();
+    	
+    	HttpRequest captured = cap.getValue();
+    	boolean foundEtag1 = false;
+    	boolean foundEtag2 = false;
+    	for(Header h : captured.getHeaders("If-None-Match")) {
+    		for(String etag : h.getValue().split(",")) {
+    			if ("\"etag1\"".equals(etag.trim())) {
+    				foundEtag1 = true;
+    			}
+    			if ("\"etag2\"".equals(etag.trim())) {
+    				foundEtag2 = true;
+    			}
+    		}
+    	}
+    	assertTrue(foundEtag1 && foundEtag2);
+    }
 }



RE: svn commit: r1043717 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/CachingHttpClient.java test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java

Posted by "Moore, Jonathan" <Jo...@Comcast.com>.
Ok, thanks for pointing that out. I'll put an update on the wiki with this guidance. :)

Jon
________________________________________
From: sebb [sebbaz@gmail.com]
Sent: Wednesday, December 08, 2010 5:54 PM
To: HttpComponents Project
Subject: Re: svn commit: r1043717 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/CachingHttpClient.java test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java

On 8 December 2010 22:04,  <jo...@apache.org> wrote:
> Author: jonm
> Date: Wed Dec  8 22:04:48 2010
> New Revision: 1043717
>
> URL: http://svn.apache.org/viewvc?rev=1043717&view=rev
> Log:
> Cache revalidation of entries now sends etags of all cached variants on
> the conditional request. (Commit of my own patch posted to
> https://issues.apache.org/jira/browse/HTTPCLIENT-1024 before I had
> commit rights).

Note that JIRA automatically adds a comment to the issue provided that
the issue number is present in the log message (as happened here).

However the normal style is to start the log message with the JIRA id
and title, followed by any additional comment, e.g.

>>>
HTTPCLIENT-1024:  cache does not validate multiple cached variants
Cache revalidation of entries now sends etags of all cached variants
on the conditional request.
Contributed by ....
<<<

Having the JIRA issue in a standard location makes it much easier to
follow when reviewing SVN history.

[But no need to change this log message.]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: svn commit: r1043717 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/CachingHttpClient.java test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java

Posted by sebb <se...@gmail.com>.
On 8 December 2010 22:04,  <jo...@apache.org> wrote:
> Author: jonm
> Date: Wed Dec  8 22:04:48 2010
> New Revision: 1043717
>
> URL: http://svn.apache.org/viewvc?rev=1043717&view=rev
> Log:
> Cache revalidation of entries now sends etags of all cached variants on
> the conditional request. (Commit of my own patch posted to
> https://issues.apache.org/jira/browse/HTTPCLIENT-1024 before I had
> commit rights).

Note that JIRA automatically adds a comment to the issue provided that
the issue number is present in the log message (as happened here).

However the normal style is to start the log message with the JIRA id
and title, followed by any additional comment, e.g.

>>>
HTTPCLIENT-1024:  cache does not validate multiple cached variants
Cache revalidation of entries now sends etags of all cached variants
on the conditional request.
Contributed by ....
<<<

Having the JIRA issue in a standard location makes it much easier to
follow when reviewing SVN history.

[But no need to change this log message.]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org