HTTPCLIENT-1542: Caching HttpClient uses absolute URIs for validation (follow-up patch, more tests)

Based on contribution by Joseph Walton <joe at kafsemo.org>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1618558 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-08-18 07:55:10 +00:00
parent 8c85040d3e
commit 1894418915
2 changed files with 32 additions and 1 deletions

View File

@ -745,7 +745,7 @@ public class CachingExec implements ClientExecChain {
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);
}

View File

@ -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;
@ -308,6 +309,36 @@ public class TestCachingExec extends TestCachingExecChain {
verifyMocks();
}
@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);