7272import org .apache .hc .core5 .http .HttpRequest ;
7373import org .apache .hc .core5 .http .HttpResponse ;
7474import org .apache .hc .core5 .http .HttpStatus ;
75- import org .apache .hc .core5 .http .ProtocolException ;
7675import org .apache .hc .core5 .http .impl .BasicEntityDetails ;
7776import org .apache .hc .core5 .http .nio .AsyncDataConsumer ;
7877import org .apache .hc .core5 .http .nio .AsyncEntityProducer ;
@@ -261,11 +260,10 @@ public void doExecute(
261260 return ;
262261 }
263262
264- // Do not attempt to cache requests with an enclosed content body
265- // To be revised when implementing QUERY support
266- if (entityProducer != null ) {
263+ final SimpleHttpRequest cacheRequest = prepareRequest (request , entityProducer );
264+ if (cacheRequest == null ) {
267265 if (LOG .isDebugEnabled ()) {
268- LOG .debug ("{} entity enclosing request cannot be served from cache " , exchangeId );
266+ LOG .debug ("{} request cannot be correctly executed and cached " , exchangeId );
269267 }
270268 chain .proceed (request , entityProducer , scope , asyncExecCallback );
271269 return ;
@@ -284,8 +282,6 @@ public void doExecute(
284282 LOG .debug ("{} request cache control: {}" , exchangeId , requestCacheControl );
285283 }
286284
287- final SimpleHttpRequest cacheRequest = prepareRequest (request , entityProducer );
288-
289285 if (!cacheableRequestPolicy .canBeServedFromCache (requestCacheControl , cacheRequest )) {
290286 if (LOG .isDebugEnabled ()) {
291287 LOG .debug ("{} request cannot be served from cache" , exchangeId );
@@ -416,10 +412,10 @@ public void cancelled() {
416412 }
417413
418414 SimpleHttpRequest prepareRequest (final HttpRequest request ,
419- final AsyncEntityProducer entityProducer ) throws ProtocolException {
415+ final AsyncEntityProducer entityProducer ) {
420416 // To be revised when implementing QUERY support
421417 if (entityProducer != null ) {
422- throw new ProtocolException ( "Caching of entity enclosing requests is not supported" ) ;
418+ return null ;
423419 }
424420 return SimpleRequestBuilder .copy (request ).build ();
425421 }
0 commit comments