You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Francois-Xavier Bonnet (JIRA)" <ji...@apache.org> on 2012/12/14 14:48:13 UTC
[jira] [Commented] (HTTPCLIENT-1277) CachingHttpClient sends a 304
Not Modified to an unconditional request
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1277?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13532302#comment-13532302 ]
Francois-Xavier Bonnet commented on HTTPCLIENT-1277:
----------------------------------------------------
I just fixed my test, there was a mistake. But the bug is here.
I tried to fix org.apache.http.impl.client.cache.CachedResponseSuitabilityChecker.canCachedResponseBeUsed(HttpHost, HttpRequest, HttpCacheEntry, Date) but there is also a problem with revalidation in org.apache.http.impl.client.cache.CachingExec.handleCacheHit(HttpRoute, HttpRequestWrapper, HttpClientContext, HttpExecutionAware, HttpCacheEntry)
> CachingHttpClient sends a 304 Not Modified to an unconditional request
> ----------------------------------------------------------------------
>
> Key: HTTPCLIENT-1277
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1277
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: Cache
> Affects Versions: 4.2.2, Snapshot
> Reporter: Francois-Xavier Bonnet
>
> When sending a conditional request, CachingHttpClient can cache the 304 response depending on the response headers. Then when sending an unconditional request, the 304 cached is reused.
> In method org.apache.http.impl.client.cache.CachedResponseSuitabilityChecker.canCachedResponseBeUsed(HttpHost, HttpRequest, HttpCacheEntry, Date) there is not test to check if the cached response is a 304 when the request is unconditional.
> Here is a unit test that is broken:
> @Test
> public void testDoesNotSend304ForNonConditionalRequest() throws Exception {
> Date now = new Date();
> Date inOneMinute = new Date(System.currentTimeMillis()+60000);
> impl = new CachingExec(mockBackend, new BasicHttpCache(),CacheConfig.DEFAULT);
> HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
> req1.addHeader("If-None-Match", "etag");
> HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
> 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("Etag", "etag");
> resp1.setHeader("Vary", "Accept-Encoding");
> 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("Etag", "etag");
> resp2.setHeader("Vary", "Accept-Encoding");
> resp2.setEntity(HttpTestUtils.makeBody(128));
> backendExpectsAnyRequestAndReturn(resp1);
> backendExpectsAnyRequestAndReturn(resp2).anyTimes();
> replayMocks();
> HttpResponse result1 = impl.execute(route, req1);
> HttpResponse result2 = impl.execute(route, req2);
> verifyMocks();
> assertEquals(HttpStatus.SC_NOT_MODIFIED, result1.getStatusLine().getStatusCode());
> assertNull(result1.getEntity());
> assertEquals(HttpStatus.SC_OK, result2.getStatusLine().getStatusCode());
> Assert.assertNotNull(result2.getEntity());
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org