You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2026/08/15 09:55:22 UTC

(httpcomponents-client) branch 5.6.x updated: Bug-fix: ResponseCachingPolicy incorrectly applies `neverCache1_1ResponsesWithQueryString` config parameter. This config parameter and related functionality will be deprecated in the next feature release and removed in the future.

This is an automated email from the ASF dual-hosted git repository.

ok2c pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/5.6.x by this push:
     new 8fd3e27b2 Bug-fix: ResponseCachingPolicy incorrectly applies `neverCache1_1ResponsesWithQueryString` config parameter. This config parameter and related functionality will be deprecated in the next feature release and removed in the future.
8fd3e27b2 is described below

commit 8fd3e27b2435b23ca403eed55ae1ef4fbf70c61a
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Aug 15 11:47:42 2026 +0200

    Bug-fix: ResponseCachingPolicy incorrectly applies `neverCache1_1ResponsesWithQueryString` config parameter. This config parameter and related functionality will be deprecated in the next feature release and removed in the future.
---
 .../http/impl/cache/ResponseCachingPolicy.java     |  2 +-
 .../http/impl/cache/TestResponseCachingPolicy.java | 23 +++++++++++-----------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java
index 93bd98e80..253e011f3 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java
@@ -117,7 +117,7 @@ public boolean isResponseCacheable(final ResponseCacheControl cacheControl, fina
             if (neverCache1_0ResponsesWithQueryString && from1_0Origin(response)) {
                 LOG.debug("Response is not cacheable as it had a query string");
                 return false;
-            } else if (!neverCache1_1ResponsesWithQueryString && !isExplicitlyCacheable(cacheControl, response)) {
+            } else if (neverCache1_1ResponsesWithQueryString && !isExplicitlyCacheable(cacheControl, response)) {
                 LOG.debug("Response is not cacheable as it is missing explicit caching headers");
                 return false;
             }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java
index a2128ef17..831bb5bf0 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java
@@ -503,27 +503,21 @@ void testResponsesThatAreSmallEnoughAreCacheable() {
     }
 
     @Test
-    void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheable() {
+    void testResponsesToGETWithQueryParamsButNoExplicitCachingAreCacheable() {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
-    }
-
-    @Test
-    void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheable() {
-        request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
+        Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
     }
 
     @Test
-    void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
-        policy = new ResponseCachingPolicy(true, true, false);
+    void testResponsesToGETWithQueryParamsAreNotCacheableWhenHTTP11QueryCachingDisabled() {
+        policy = new ResponseCachingPolicy(true, false, true);
         request = new BasicHttpRequest("GET", "/foo?s=bar");
         Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
     }
 
     @Test
-    void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
-        policy = new ResponseCachingPolicy(true, true, false);
+    void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheable() {
+        policy = new ResponseCachingPolicy(true, false, true);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
         Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
     }
@@ -565,6 +559,7 @@ void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0
 
     @Test
     void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
+        policy = new ResponseCachingPolicy(true, true, false);
         request = new BasicHttpRequest("GET", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
@@ -573,6 +568,7 @@ void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
 
     @Test
     void headsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
+        policy = new ResponseCachingPolicy(true, true, false);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
@@ -642,6 +638,7 @@ void headsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpi
 
     @Test
     void getsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
+        policy = new ResponseCachingPolicy(true, true, false);
         request = new BasicHttpRequest("GET", "/foo?s=bar");
         response.setHeader(HttpHeaders.VIA, "1.0 someproxy");
         Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
@@ -649,6 +646,7 @@ void getsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
 
     @Test
     void headsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
+        policy = new ResponseCachingPolicy(true, true, false);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
         response.setHeader(HttpHeaders.VIA, "1.0 someproxy");
         Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
@@ -902,6 +900,7 @@ void testIsResponseCacheable() {
         policy = new ResponseCachingPolicy(true, false, true);
         response.setCode(HttpStatus.SC_OK);
         response.setHeader("Date", DateUtils.formatStandardDate(now));
+        responseCacheControl = ResponseCacheControl.builder().setMaxAge(3600).build();
         assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
     }