From 194e4f528973a7139c178f198fde644d4ea03cb3 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 1 Jan 2018 16:52:50 +0100 Subject: [PATCH] Corrected handling of request with non-repeatable by caching request execution interceptors --- .../apache/hc/client5/http/impl/cache/AsyncCachingExec.java | 5 +++-- .../org/apache/hc/client5/http/impl/cache/CachingExec.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java index 179fbcd8a..c812b12bd 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java @@ -711,7 +711,8 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH final Date responseDate1 = getCurrentDate(); final AsyncExecCallback callback1; - if (revalidationResponseIsTooOld(backendResponse1, cacheEntry)) { + if (revalidationResponseIsTooOld(backendResponse1, cacheEntry) + && (entityProducer == null || entityProducer.isRepeatable())) { final HttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest( scope.originalRequest); @@ -805,7 +806,7 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH @Override public void completed(final Map variants) { - if (variants != null && !variants.isEmpty()) { + if (variants != null && !variants.isEmpty() && (entityProducer == null || entityProducer.isRepeatable())) { negotiateResponseFromVariants(target, request, entityProducer, scope, chain, asyncExecCallback, variants); } else { callBackend(target, request, entityProducer, scope, chain, asyncExecCallback); diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java index 724fa8a8c..7fb7e426b 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java @@ -447,7 +447,8 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler { return callBackend(target, request, scope, chain); } - if (revalidationResponseIsTooOld(backendResponse, matchingVariant.getEntry())) { + if (revalidationResponseIsTooOld(backendResponse, matchingVariant.getEntry()) + && (request.getEntity() == null || request.getEntity().isRepeatable())) { EntityUtils.consume(backendResponse.getEntity()); backendResponse.close(); final ClassicHttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request);