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/07/15 16:33:29 UTC

(httpcomponents-client) branch master updated: HTTP cache protocol interceptors to route requests that cannot be correctly represented as SimpleHttpRequest directly to the request execution pipeline bypassing the caching layer

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

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


The following commit(s) were added to refs/heads/master by this push:
     new b3676f3a7 HTTP cache protocol interceptors to route requests that cannot be correctly represented as SimpleHttpRequest directly to the request execution pipeline bypassing the caching layer
b3676f3a7 is described below

commit b3676f3a78ac854451b19f29409cf62550f3c3e8
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Jul 15 18:30:15 2026 +0200

    HTTP cache protocol interceptors to route requests that cannot be correctly represented as SimpleHttpRequest directly to the request execution pipeline bypassing the caching layer
---
 .../hc/client5/http/impl/cache/AsyncCachingExec.java      | 14 +++++---------
 .../apache/hc/client5/http/impl/cache/CachingExec.java    | 15 +++++----------
 2 files changed, 10 insertions(+), 19 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 d0aa3cfd7..01141b32c 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
@@ -72,7 +72,6 @@
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.impl.BasicEntityDetails;
 import org.apache.hc.core5.http.nio.AsyncDataConsumer;
 import org.apache.hc.core5.http.nio.AsyncEntityProducer;
@@ -261,11 +260,10 @@ public void doExecute(
             return;
         }
 
-        // Do not attempt to cache requests with an enclosed content body
-        // To be revised when implementing QUERY support
-        if (entityProducer != null) {
+        final SimpleHttpRequest cacheRequest = prepareRequest(request, entityProducer);
+        if (cacheRequest == null) {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("{} entity enclosing request cannot be served from cache", exchangeId);
+                LOG.debug("{} request cannot be correctly executed and cached", exchangeId);
             }
             chain.proceed(request, entityProducer, scope, asyncExecCallback);
             return;
@@ -284,8 +282,6 @@ public void doExecute(
             LOG.debug("{} request cache control: {}", exchangeId, requestCacheControl);
         }
 
-        final SimpleHttpRequest cacheRequest = prepareRequest(request, entityProducer);
-
         if (!cacheableRequestPolicy.canBeServedFromCache(requestCacheControl, cacheRequest)) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("{} request cannot be served from cache", exchangeId);
@@ -416,10 +412,10 @@ public void cancelled() {
     }
 
     SimpleHttpRequest prepareRequest(final HttpRequest request,
-                                     final AsyncEntityProducer entityProducer) throws ProtocolException {
+                                     final AsyncEntityProducer entityProducer) {
         // To be revised when implementing QUERY support
         if (entityProducer != null) {
-            throw new ProtocolException("Caching of entity enclosing requests is not supported");
+            return null;
         }
         return SimpleRequestBuilder.copy(request).build();
     }
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 7cff168a7..81f1abc93 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
@@ -61,7 +61,6 @@
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.io.entity.StringEntity;
@@ -158,12 +157,10 @@ ClassicHttpResponse doExecute(
             return new BasicClassicHttpResponse(HttpStatus.SC_NOT_IMPLEMENTED);
         }
 
-        // Do not attempt to cache requests with an enclosed content body
-        // To be revised when implementing QUERY support
-        final HttpEntity requestEntity = request.getEntity();
-        if (requestEntity != null) {
+        final SimpleHttpRequest cacheRequest = prepareRequest(request);
+        if (cacheRequest == null) {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("{} entity enclosing request cannot be served from cache", exchangeId);
+                LOG.debug("{} request cannot be correctly executed and cached", exchangeId);
             }
             return chain.proceed(request, scope);
         }
@@ -176,8 +173,6 @@ ClassicHttpResponse doExecute(
             CacheControlHeaderGenerator.INSTANCE.generate(requestCacheControl, request);
         }
 
-        final SimpleHttpRequest cacheRequest = prepareRequest(request);
-
         if (LOG.isDebugEnabled()) {
             LOG.debug("Request cache control: {}", requestCacheControl);
         }
@@ -226,10 +221,10 @@ private static ClassicHttpResponse convert(final SimpleHttpResponse cacheRespons
         return response;
     }
 
-    SimpleHttpRequest prepareRequest(final ClassicHttpRequest request) throws ProtocolException {
+    SimpleHttpRequest prepareRequest(final ClassicHttpRequest request) {
         // To be revised when implementing QUERY support
         if (request.getEntity() != null) {
-            throw new ProtocolException("Caching of entity enclosing requests is not supported");
+            return null;
         }
         return SimpleRequestBuilder.copy(request).build();
     }