From e7b3a5316c49c9edfc3d26ef3e173103d672013c Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 14 Oct 2024 14:00:52 +0200 Subject: [PATCH] Bug fix: response Cache-Control attribute does not get updated in the cache execution context in case of a cache miss --- .../org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java | 2 ++ .../java/org/apache/hc/client5/http/impl/cache/CachingExec.java | 2 ++ 2 files changed, 4 insertions(+) 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 83941c17d..9848f5594 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 @@ -523,7 +523,9 @@ public void cancelled() { return asyncExecCallback.handleResponse(backendResponse, entityDetails); } + final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext); final ResponseCacheControl responseCacheControl = CacheControlHeaderParser.INSTANCE.parse(backendResponse); + context.setResponseCacheControl(responseCacheControl); final boolean cacheable = responseCachingPolicy.isResponseCacheable(responseCacheControl, request, backendResponse); if (cacheable) { storeRequestIfModifiedSinceFor304Response(request, backendResponse); 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 6ab119400..f794fe18a 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 @@ -467,7 +467,9 @@ ClassicHttpResponse handleBackendResponse( } return backendResponse; } + final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext); final ResponseCacheControl responseCacheControl = CacheControlHeaderParser.INSTANCE.parse(backendResponse); + context.setResponseCacheControl(responseCacheControl); final boolean cacheable = responseCachingPolicy.isResponseCacheable(responseCacheControl, request, backendResponse); if (cacheable) { storeRequestIfModifiedSinceFor304Response(request, backendResponse);