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/14 09:54:17 UTC

(httpcomponents-client) branch 5.6.x updated: Removed invalid request version check from ResponseCachingPolicy

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 93ae3699e Removed invalid request version check from ResponseCachingPolicy
93ae3699e is described below

commit 93ae3699ed0ceced7e0270501b915d7cee3395d2
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Aug 14 11:42:43 2026 +0200

    Removed invalid request version check from ResponseCachingPolicy
---
 .../client5/http/impl/cache/ResponseCachingPolicy.java   |  8 --------
 .../http/impl/cache/TestResponseCachingPolicy.java       | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 8 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 9672fe2dc..93bd98e80 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
@@ -90,14 +90,6 @@ public ResponseCachingPolicy(
      * @return {@code true} if response is cacheable
      */
     public boolean isResponseCacheable(final ResponseCacheControl cacheControl, final HttpRequest request, final HttpResponse response) {
-        final ProtocolVersion version = request.getVersion() != null ? request.getVersion() : HttpVersion.DEFAULT;
-        if (version.compareToVersion(HttpVersion.HTTP_1_1) > 0) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Protocol version {} is non-cacheable", version);
-            }
-            return false;
-        }
-
         // Presently only GET and HEAD methods are supported
         final String httpMethod = request.getMethod();
         if (!Method.GET.isSame(httpMethod) && !Method.HEAD.isSame(httpMethod)) {
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 bdddf7cfe..a2128ef17 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
@@ -1000,4 +1000,20 @@ void testMustRevalidateWithAuthorizationIsCacheable() {
                 "Response with must-revalidate and Authorization header should be cacheable in shared cache.");
     }
 
+    @Test
+    void testHttp2_0HintCacheable() {
+        request = new BasicHttpRequest("GET", "/");
+        request.setVersion(HttpVersion.HTTP_2);
+        response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
+        Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
+    }
+
+    @Test
+    void testHttp1_0HintCacheable() {
+        request = new BasicHttpRequest("GET", "/");
+        request.setVersion(HttpVersion.HTTP_1_0);
+        response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
+        Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
+    }
+
 }
\ No newline at end of file