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 2021/11/12 21:21:10 UTC

[httpcomponents-client] branch master updated (fc411fa -> 4d0caa4)

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

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


    omit fc411fa  Fix typo method and class. Deprecate the old ones.
    omit 6cce828  Updated examples and unit tests to make use of lambda expressions for response message processing
     new 0e8adf7  Updated examples and unit tests to make use of lambda expressions for response message processing
     new 4d0caa4  Fix typo method and class. Deprecate the old ones.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (fc411fa)
            \
             N -- N -- N   refs/heads/master (4d0caa4)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../hc/client5/testing/sync/TestClientRequestExecution.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

[httpcomponents-client] 02/02: Fix typo method and class. Deprecate the old ones.

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4d0caa4f423aadfb0fabc87c11a9962f5c7e4d7a
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Thu Nov 11 14:11:24 2021 +0100

    Fix typo method and class. Deprecate the old ones.
---
 .../client5/http/impl/cache/AsyncCachingExec.java  |  2 +-
 .../http/impl/cache/BasicHttpAsyncCache.java       |  2 +-
 .../hc/client5/http/impl/cache/BasicHttpCache.java |  2 +-
 .../http/impl/cache/CacheInvalidatorBase.java      |  2 +-
 .../http/impl/cache/CacheUpdateHandler.java        |  2 +-
 .../hc/client5/http/impl/cache/CachingExec.java    |  2 +-
 .../client5/http/impl/cache/CachingExecBase.java   |  5 +++-
 .../impl/cache/DefaultAsyncCacheInvalidator.java   |  8 +++---
 .../http/impl/cache/DefaultCacheInvalidator.java   |  8 +++---
 .../client5/http/impl/cache/HttpCacheSupport.java  | 17 ++++++++++++
 ... => IgnoreCompleteExceptionFutureCallback.java} |  9 ++++--
 .../IgnoreCompleteExceptonFutureCallback.java      | 32 +++++++---------------
 12 files changed, 51 insertions(+), 40 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 bbbd75c..6cc9832 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
@@ -231,7 +231,7 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
             return;
         }
 
-        final SimpleHttpResponse fatalErrorResponse = getFatallyNoncompliantResponse(request, context);
+        final SimpleHttpResponse fatalErrorResponse = getFatallyNonCompliantResponse(request, context);
         if (fatalErrorResponse != null) {
             triggerResponse(fatalErrorResponse, scope, asyncExecCallback);
             return;
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
index e3bf75b..508c814 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java
@@ -412,7 +412,7 @@ class BasicHttpAsyncCache implements HttpAsyncCache {
         }
         final String cacheKey = cacheKeyGenerator.generateKey(host, request);
         try {
-            final HttpCacheEntry entry = cacheUpdateHandler.createtCacheEntry(request, originResponse, content, requestSent, responseReceived);
+            final HttpCacheEntry entry = cacheUpdateHandler.createCacheEntry(request, originResponse, content, requestSent, responseReceived);
             return storeInCache(cacheKey, host, request, entry, new FutureCallback<Boolean>() {
 
                 @Override
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
index 70e5272..e6a7c1d 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java
@@ -270,7 +270,7 @@ class BasicHttpCache implements HttpCache {
         }
         final String cacheKey = cacheKeyGenerator.generateKey(host, request);
         try {
-            final HttpCacheEntry entry = cacheUpdateHandler.createtCacheEntry(request, originResponse, content, requestSent, responseReceived);
+            final HttpCacheEntry entry = cacheUpdateHandler.createCacheEntry(request, originResponse, content, requestSent, responseReceived);
             storeInCache(cacheKey, host, request, entry);
             return entry;
         } catch (final ResourceIOException ex) {
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java
index feaf95e..e7a9c66 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java
@@ -68,7 +68,7 @@ class CacheInvalidatorBase {
         if (h == null) {
             return null;
         }
-        final URI locationUri = HttpCacheSupport.normalizeQuetly(h.getValue());
+        final URI locationUri = HttpCacheSupport.normalizeQuietly(h.getValue());
         if (locationUri == null) {
             return requestUri;
         }
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java
index 7416766..bdb0d32 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java
@@ -65,7 +65,7 @@ class CacheUpdateHandler {
     /**
      * Creates a cache entry for the given request, origin response message and response content.
      */
-    public HttpCacheEntry createtCacheEntry(
+    public HttpCacheEntry createCacheEntry(
             final HttpRequest request,
             final HttpResponse originResponse,
             final ByteArrayBuffer content,
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 1272401..f72ebeb 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
@@ -178,7 +178,7 @@ class CachingExec extends CachingExecBase implements ExecChainHandler {
             return new BasicClassicHttpResponse(HttpStatus.SC_NOT_IMPLEMENTED);
         }
 
-        final SimpleHttpResponse fatalErrorResponse = getFatallyNoncompliantResponse(request, context);
+        final SimpleHttpResponse fatalErrorResponse = getFatallyNonCompliantResponse(request, context);
         if (fatalErrorResponse != null) {
             return convert(fatalErrorResponse, scope);
         }
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExecBase.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExecBase.java
index 3a7a462..cec75bf 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExecBase.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExecBase.java
@@ -139,7 +139,10 @@ public class CachingExecBase {
         return cacheUpdates.get();
     }
 
-    SimpleHttpResponse getFatallyNoncompliantResponse(
+    /**
+     * @since 5.2
+     */
+    SimpleHttpResponse getFatallyNonCompliantResponse(
             final HttpRequest request,
             final HttpContext context) {
         final List<RequestProtocolError> fatalError = requestCompliance.requestIsFatallyNonCompliant(request);
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
index 77b720b..226c644 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
@@ -100,7 +100,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
             final HttpAsyncCacheStorage storage,
             final FutureCallback<Boolean> callback) {
         final String s = HttpCacheSupport.getRequestUri(request, host);
-        final URI uri = HttpCacheSupport.normalizeQuetly(s);
+        final URI uri = HttpCacheSupport.normalizeQuietly(s);
         final String cacheKey = uri != null ? cacheKeyResolver.resolve(uri) : s;
         return storage.getEntry(cacheKey, new FutureCallback<HttpCacheEntry>() {
 
@@ -122,7 +122,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
                         }
                         final Header clHdr = request.getFirstHeader("Content-Location");
                         if (clHdr != null) {
-                            final URI contentLocation = HttpCacheSupport.normalizeQuetly(clHdr.getValue());
+                            final URI contentLocation = HttpCacheSupport.normalizeQuietly(clHdr.getValue());
                             if (contentLocation != null) {
                                 if (!flushAbsoluteUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage)) {
                                     flushRelativeUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage);
@@ -131,7 +131,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
                         }
                         final Header lHdr = request.getFirstHeader("Location");
                         if (lHdr != null) {
-                            final URI location = HttpCacheSupport.normalizeQuetly(lHdr.getValue());
+                            final URI location = HttpCacheSupport.normalizeQuietly(lHdr.getValue());
                             if (location != null) {
                                 flushAbsoluteUriFromSameHost(uri, location, cacheKeyResolver, storage);
                             }
@@ -189,7 +189,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
         final int status = response.getCode();
         if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_REDIRECTION) {
             final String s = HttpCacheSupport.getRequestUri(request, host);
-            final URI requestUri = HttpCacheSupport.normalizeQuetly(s);
+            final URI requestUri = HttpCacheSupport.normalizeQuietly(s);
             if (requestUri != null) {
                 final List<String> cacheKeys = new ArrayList<>(2);
                 final URI contentLocation = getContentLocationURI(requestUri, response);
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java
index debc1a5..b57bba9 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java
@@ -86,7 +86,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
             final Resolver<URI, String> cacheKeyResolver,
             final HttpCacheStorage storage) {
         final String s = HttpCacheSupport.getRequestUri(request, host);
-        final URI uri = HttpCacheSupport.normalizeQuetly(s);
+        final URI uri = HttpCacheSupport.normalizeQuietly(s);
         final String cacheKey = uri != null ? cacheKeyResolver.resolve(uri) : s;
         final HttpCacheEntry parent = getEntry(storage, cacheKey);
 
@@ -106,7 +106,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
                 }
                 final Header clHdr = request.getFirstHeader("Content-Location");
                 if (clHdr != null) {
-                    final URI contentLocation = HttpCacheSupport.normalizeQuetly(clHdr.getValue());
+                    final URI contentLocation = HttpCacheSupport.normalizeQuietly(clHdr.getValue());
                     if (contentLocation != null) {
                         if (!flushAbsoluteUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage)) {
                             flushRelativeUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage);
@@ -115,7 +115,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
                 }
                 final Header lHdr = request.getFirstHeader("Location");
                 if (lHdr != null) {
-                    final URI location = HttpCacheSupport.normalizeQuetly(lHdr.getValue());
+                    final URI location = HttpCacheSupport.normalizeQuietly(lHdr.getValue());
                     if (location != null) {
                         flushAbsoluteUriFromSameHost(uri, location, cacheKeyResolver, storage);
                     }
@@ -159,7 +159,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
             return;
         }
         final String s = HttpCacheSupport.getRequestUri(request, host);
-        final URI uri = HttpCacheSupport.normalizeQuetly(s);
+        final URI uri = HttpCacheSupport.normalizeQuietly(s);
         if (uri == null) {
             return;
         }
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
index 1233062..67e03f1 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
@@ -123,7 +123,9 @@ public final class HttpCacheSupport {
 
     /**
      * Lenient URI parser that normalizes valid {@link URI}s and returns {@code null} for malformed URIs.
+     * @deprecated Use {@link #normalizeQuietly(String)}
      */
+    @Deprecated
     public static URI normalizeQuetly(final String requestUri) {
         if (requestUri == null) {
             return null;
@@ -135,4 +137,19 @@ public final class HttpCacheSupport {
         }
     }
 
+    /**
+     * Lenient URI parser that normalizes valid {@link URI}s and returns {@code null} for malformed URIs.
+     * @since 5.2
+     */
+    public static URI normalizeQuietly(final String requestUri) {
+        if (requestUri == null) {
+            return null;
+        }
+        try {
+            return normalize(new URI(requestUri));
+        } catch (final URISyntaxException ex) {
+            return null;
+        }
+    }
+
 }
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptionFutureCallback.java
similarity index 89%
copy from httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java
copy to httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptionFutureCallback.java
index 3d108e1..0191294 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptionFutureCallback.java
@@ -30,13 +30,16 @@ import org.apache.hc.core5.concurrent.FutureCallback;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class IgnoreCompleteExceptonFutureCallback<T> implements FutureCallback<T> {
+/**
+ * @since 5.2
+ */
+public class IgnoreCompleteExceptionFutureCallback<T> implements FutureCallback<T> {
 
     private final FutureCallback<T> callback;
 
-    private static final Logger LOG = LoggerFactory.getLogger(IgnoreCompleteExceptonFutureCallback.class);
+    private static final Logger LOG = LoggerFactory.getLogger(IgnoreCompleteExceptionFutureCallback.class);
 
-    public IgnoreCompleteExceptonFutureCallback(final FutureCallback<T> callback) {
+    public IgnoreCompleteExceptionFutureCallback(final FutureCallback<T> callback) {
         super();
         this.callback = callback;
     }
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java
index 3d108e1..d693807 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/IgnoreCompleteExceptonFutureCallback.java
@@ -27,43 +27,31 @@
 package org.apache.hc.client5.http.async.methods;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-public class IgnoreCompleteExceptonFutureCallback<T> implements FutureCallback<T> {
-
-    private final FutureCallback<T> callback;
-
-    private static final Logger LOG = LoggerFactory.getLogger(IgnoreCompleteExceptonFutureCallback.class);
+/**
+ * @deprecated Use {@link IgnoreCompleteExceptionFutureCallback}
+ * @since 5.2
+ */
+@Deprecated
+public class IgnoreCompleteExceptonFutureCallback<T> extends IgnoreCompleteExceptionFutureCallback<T> implements FutureCallback<T> {
 
     public IgnoreCompleteExceptonFutureCallback(final FutureCallback<T> callback) {
-        super();
-        this.callback = callback;
+        super(callback);
     }
 
     @Override
     public void completed(final T result) {
-        if (callback != null) {
-            try {
-                callback.completed(result);
-            } catch (final Exception ex) {
-                LOG.error(ex.getMessage(), ex);
-            }
-        }
+        super.completed(result);
     }
 
     @Override
     public void failed(final Exception ex) {
-        if (callback != null) {
-            callback.failed(ex);
-        }
+        super.failed(ex);
     }
 
     @Override
     public void cancelled() {
-        if (callback != null) {
-            callback.cancelled();
-        }
+       super.cancelled();
     }
 
 }

[httpcomponents-client] 01/02: Updated examples and unit tests to make use of lambda expressions for response message processing

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0e8adf79dcc82e8ddeb24f5c9988138619845c03
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Nov 12 22:16:43 2021 +0100

    Updated examples and unit tests to make use of lambda expressions for response message processing
---
 .../testing/sync/TestBasicConnectionManager.java   |   6 +-
 .../testing/sync/TestClientAuthentication.java     | 118 ++++++----
 .../sync/TestClientAuthenticationFakeNTLM.java     |  45 ++--
 .../testing/sync/TestClientRequestExecution.java   |  77 ++++---
 .../client5/testing/sync/TestConnectionReuse.java  |  41 ++--
 .../client5/testing/sync/TestContentCodings.java   |  59 +++--
 .../testing/sync/TestCookieVirtualHost.java        |  37 ++-
 .../testing/sync/TestIdleConnectionEviction.java   |  12 +-
 .../testing/sync/TestMalformedServerResponse.java  |  19 +-
 .../sync/TestMinimalClientRequestExecution.java    |  11 +-
 .../hc/client5/testing/sync/TestRedirects.java     | 254 ++++++++++-----------
 .../hc/client5/testing/sync/TestSPNegoScheme.java  |  17 +-
 .../testing/sync/TestStatefulConnManagement.java   |  30 +--
 .../testing/sync/TestWindowsNegotiateScheme.java   |   6 +-
 .../client5/http/examples/ClientAbortMethod.java   |  22 +-
 .../http/examples/ClientAuthentication.java        |  11 +-
 .../http/examples/ClientChunkEncodedPost.java      |  11 +-
 .../client5/http/examples/ClientConfiguration.java |  41 ++--
 .../http/examples/ClientConnectionConfig.java      |   7 +-
 .../http/examples/ClientConnectionRelease.java     |  74 ------
 .../client5/http/examples/ClientCustomContext.java |   9 +-
 .../examples/ClientCustomPublicSuffixList.java     |  13 +-
 .../hc/client5/http/examples/ClientCustomSSL.java  |  12 +-
 .../examples/ClientEvictExpiredConnections.java    |   9 +-
 .../client5/http/examples/ClientExecuteProxy.java  |  11 +-
 .../client5/http/examples/ClientExecuteSOCKS.java  |  24 +-
 .../hc/client5/http/examples/ClientFormLogin.java  |  26 +--
 .../client5/http/examples/ClientInterceptors.java  |  11 +-
 .../examples/ClientMultiThreadedExecution.java     |   6 +-
 .../http/examples/ClientMultipartFormPost.java     |  11 +-
 .../ClientPreemptiveBasicAuthentication.java       |  11 +-
 .../ClientPreemptiveDigestAuthentication.java      |   9 +-
 .../http/examples/ClientProxyAuthentication.java   |  11 +-
 ...rtMethod.java => ClientResponseProcessing.java} |  33 ++-
 .../http/examples/ClientWithResponseHandler.java   |  73 ------
 .../classic/TestHttpClientBuilderInterceptors.java |   8 +-
 36 files changed, 556 insertions(+), 619 deletions(-)

diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
index 65033af..e90832a 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
@@ -27,7 +27,6 @@
 package org.apache.hc.client5.testing.sync;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -42,10 +41,11 @@ public class TestBasicConnectionManager extends LocalServerTestBase {
 
         final HttpHost target = start();
         final HttpGet get = new HttpGet("/random/1024");
-        try (CloseableHttpResponse response = this.httpclient.execute(target, get)) {
+        this.httpclient.execute(target, get, response -> {
             Assert.assertEquals(200, response.getCode());
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
     }
 
     @Test
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java
index 80c2834..32cf21e 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java
@@ -53,7 +53,6 @@ import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
 import org.apache.hc.client5.http.impl.auth.BasicScheme;
 import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
 import org.apache.hc.client5.http.impl.auth.CredentialsProviderBuilder;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.client5.testing.BasicTestAuthenticator;
 import org.apache.hc.client5.testing.auth.Authenticator;
@@ -108,12 +107,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
         context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+        this.httpclient.execute(target, httpget, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
         Mockito.verify(credsProvider).getCredentials(
                 Mockito.eq(new AuthScope(target, "test realm", "basic")), Mockito.any());
     }
@@ -130,12 +130,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
         context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+        this.httpclient.execute(target, httpget, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
         Mockito.verify(credsProvider).getCredentials(
                 Mockito.eq(new AuthScope(target, "test realm", "basic")), Mockito.any());
     }
@@ -152,12 +153,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
 
         final HttpHost target = start();
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+        this.httpclient.execute(target, httpget, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
         Mockito.verify(credsProvider).getCredentials(
                 Mockito.eq(new AuthScope(target, "test realm", "basic")), Mockito.any());
     }
@@ -182,11 +184,12 @@ public class TestClientAuthentication extends LocalServerTestBase {
                 .thenReturn(new UsernamePasswordCredentials("test", "test".toCharArray()));
         context.setCredentialsProvider(credsProvider);
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpput, context)) {
+        this.httpclient.execute(target, httpput, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity);
-        }
+            return null;
+        });
     }
 
     @Test
@@ -208,12 +211,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
                 .thenReturn(new UsernamePasswordCredentials("test", "boom".toCharArray()));
         context.setCredentialsProvider(credsProvider);
 
-        try (final CloseableHttpResponse response = this.httpclient.execute(target, httpput, context)) {
+        this.httpclient.execute(target, httpput, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(401, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
     }
 
     @Test
@@ -230,12 +234,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
                 .thenReturn(new UsernamePasswordCredentials("test", "test".toCharArray()));
         context.setCredentialsProvider(credsProvider);
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httppost, context)) {
+        this.httpclient.execute(target, httppost, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
         Mockito.verify(credsProvider).getCredentials(
                 Mockito.eq(new AuthScope(target, "test realm", "basic")), Mockito.any());
     }
@@ -259,12 +264,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
                 .thenReturn(new UsernamePasswordCredentials("test", "test".toCharArray()));
         context.setCredentialsProvider(credsProvider);
 
-        try (final CloseableHttpResponse response = this.httpclient.execute(target, httppost, context)) {
+        this.httpclient.execute(target, httppost, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(401, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
     }
 
     @Test
@@ -285,12 +291,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
 
         for (int i = 0; i < 5; i++) {
             final HttpGet httpget = new HttpGet("/");
-            try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+            this.httpclient.execute(target, httpget, context, response -> {
                 final HttpEntity entity1 = response.getEntity();
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
                 Assert.assertNotNull(entity1);
                 EntityUtils.consume(entity1);
-            }
+                return null;
+            });
         }
 
         Mockito.verify(authStrategy).select(Mockito.any(), Mockito.any(), Mockito.any());
@@ -322,12 +329,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
 
         for (final String requestPath: new String[] {"/blah/a", "/blah/b?huh", "/blah/c", "/bl%61h/%61"}) {
             final HttpGet httpget = new HttpGet(requestPath);
-            try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+            this.httpclient.execute(target, httpget, context, response -> {
                 final HttpEntity entity1 = response.getEntity();
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
                 Assert.assertNotNull(entity1);
                 EntityUtils.consume(entity1);
-            }
+                return null;
+            });
         }
 
         // There should be only single auth strategy call for all successful message exchanges
@@ -343,12 +351,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
 
         for (final String requestPath: new String[] {"/blah/a", "/yada/a", "/blah/blah/", "/buh/a"}) {
             final HttpGet httpget = new HttpGet(requestPath);
-            try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+            this.httpclient.execute(target, httpget, context, response -> {
                 final HttpEntity entity1 = response.getEntity();
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
                 Assert.assertNotNull(entity1);
                 EntityUtils.consume(entity1);
-            }
+                return null;
+            });
         }
 
         // There should be an auth strategy call for all successful message exchanges
@@ -402,30 +411,33 @@ public class TestClientAuthentication extends LocalServerTestBase {
 
         final HttpGet httpget1 = new HttpGet("/this");
 
-        try (final ClassicHttpResponse response1 = this.httpclient.execute(target, httpget1, context)) {
-            final HttpEntity entity1 = response1.getEntity();
-            Assert.assertEquals(HttpStatus.SC_OK, response1.getCode());
+        this.httpclient.execute(target, httpget1, context, response -> {
+            final HttpEntity entity1 = response.getEntity();
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity1);
             EntityUtils.consume(entity1);
-        }
+            return null;
+        });
 
         final HttpGet httpget2 = new HttpGet("/this");
 
-        try (final ClassicHttpResponse response2 = this.httpclient.execute(target, httpget2, context)) {
-            final HttpEntity entity2 = response2.getEntity();
-            Assert.assertEquals(HttpStatus.SC_OK, response2.getCode());
+        this.httpclient.execute(target, httpget2, context, response -> {
+            final HttpEntity entity2 = response.getEntity();
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity2);
             EntityUtils.consume(entity2);
-        }
+            return null;
+        });
 
         final HttpGet httpget3 = new HttpGet("/that");
 
-        try (final ClassicHttpResponse response3 = this.httpclient.execute(target, httpget3, context)) {
-            final HttpEntity entity3 = response3.getEntity();
-            Assert.assertEquals(HttpStatus.SC_OK, response3.getCode());
+        this.httpclient.execute(target, httpget3, context, response -> {
+            final HttpEntity entity3 = response.getEntity();
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity3);
             EntityUtils.consume(entity3);
-        }
+            return null;
+        });
 
         Mockito.verify(authStrategy, Mockito.times(2)).select(Mockito.any(), Mockito.any(), Mockito.any());
     }
@@ -437,7 +449,7 @@ public class TestClientAuthentication extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet("http://test:test@" +  target.toHostString() + "/");
 
         final HttpClientContext context = HttpClientContext.create();
-        Assert.assertThrows(ClientProtocolException.class, () -> this.httpclient.execute(target, httpget, context));
+        Assert.assertThrows(ClientProtocolException.class, () -> this.httpclient.execute(target, httpget, context, response -> null));
     }
 
     @Test
@@ -454,12 +466,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
         context.setAuthCache(authCache);
 
         final HttpGet httpget = new HttpGet("/");
-        try (final ClassicHttpResponse response1 = this.httpclient.execute(target, httpget, context)) {
-            final HttpEntity entity1 = response1.getEntity();
-            Assert.assertEquals(HttpStatus.SC_OK, response1.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            final HttpEntity entity1 = response.getEntity();
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity1);
             EntityUtils.consume(entity1);
-        }
+            return null;
+        });
 
         Mockito.verify(authenticator).authenticate(Mockito.any(), Mockito.any(), Mockito.any());
     }
@@ -479,12 +492,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
                 .build());
 
         final HttpGet httpget = new HttpGet("/");
-        try (final ClassicHttpResponse response1 = this.httpclient.execute(target, httpget, context)) {
-            final HttpEntity entity1 = response1.getEntity();
-            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            final HttpEntity entity1 = response.getEntity();
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
             Assert.assertNotNull(entity1);
             EntityUtils.consume(entity1);
-        }
+            return null;
+        });
 
         Mockito.verify(authenticator).authenticate(Mockito.any(), Mockito.any(), Mockito.any());
     }
@@ -519,11 +533,12 @@ public class TestClientAuthentication extends LocalServerTestBase {
         context.setCredentialsProvider(credsProvider);
 
         final HttpGet httpget = new HttpGet("/");
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+        this.httpclient.execute(target, httpget, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, response.getCode());
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
     }
 
     @Test
@@ -550,10 +565,11 @@ public class TestClientAuthentication extends LocalServerTestBase {
         for (int i = 0; i < 2; i++) {
             final HttpGet httpget = new HttpGet("/");
 
-            try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+            this.httpclient.execute(target, httpget, context, response -> {
                 EntityUtils.consume(response.getEntity());
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            }
+                return null;
+            });
         }
     }
 
@@ -623,12 +639,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
         for (int i = 0; i < 10; i++) {
             final HttpGet httpget = new HttpGet("/");
             httpget.setConfig(config);
-            try (final CloseableHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+            this.httpclient.execute(target, httpget, context, response -> {
                 final HttpEntity entity = response.getEntity();
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
                 Assert.assertNotNull(entity);
                 EntityUtils.consume(entity);
-            }
+                return null;
+            });
         }
     }
 
@@ -654,12 +671,13 @@ public class TestClientAuthentication extends LocalServerTestBase {
         context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+        this.httpclient.execute(target, httpget, context, response -> {
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
             Assert.assertNotNull(entity);
             EntityUtils.consume(entity);
-        }
+            return null;
+        });
         Mockito.verify(credsProvider).getCredentials(
                 Mockito.eq(new AuthScope(target, "test realm", "basic")), Mockito.any());
     }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java
index f4a3d9e..6abad83 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java
@@ -82,10 +82,11 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
         final HttpContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("/");
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        EntityUtils.consume(response.getEntity());
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
-                response.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
     }
 
     static class NtlmType2MessageResponseHandler implements HttpRequestHandler {
@@ -129,10 +130,11 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
         final HttpContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("/");
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        EntityUtils.consume(response.getEntity());
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
-                response.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
     }
 
     @Test
@@ -153,10 +155,11 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
         final HttpContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("/");
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        EntityUtils.consume(response.getEntity());
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
-                response.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
     }
 
     static class NtlmType2MessageOnlyResponseHandler implements HttpRequestHandler {
@@ -192,10 +195,11 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
                 .build());
         final HttpGet httpget = new HttpGet("/");
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        EntityUtils.consume(response.getEntity());
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
-                response.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
     }
 
     @Test
@@ -212,10 +216,11 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
                 .build());
         final HttpGet httpget = new HttpGet("/");
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        EntityUtils.consume(response.getEntity());
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
-                response.getCode());
+        this.httpclient.execute(target, httpget, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
index bfb16c3..f2b3e87 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
@@ -158,16 +158,17 @@ public class TestClientRequestExecution extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/");
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, httpget, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            final HttpRequest reqWrapper = context.getRequest();
 
-        final HttpRequest reqWrapper = context.getRequest();
-
-        Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
 
-        final Header[] myheaders = reqWrapper.getHeaders("my-header");
-        Assert.assertNotNull(myheaders);
-        Assert.assertEquals(1, myheaders.length);
+            final Header[] myheaders = reqWrapper.getHeaders("my-header");
+            Assert.assertNotNull(myheaders);
+            Assert.assertEquals(1, myheaders.length);
+            return null;
+        });
     }
 
     @Test
@@ -218,7 +219,7 @@ public class TestClientRequestExecution extends LocalServerTestBase {
                         new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                         -1, null));
         Assert.assertThrows(IOException.class, () ->
-                this.httpclient.execute(target, httppost, context));
+                this.httpclient.execute(target, httppost, context, response -> null));
     }
 
     @Test
@@ -229,10 +230,11 @@ public class TestClientRequestExecution extends LocalServerTestBase {
 
         final HttpClientContext context = HttpClientContext.create();
         final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", "{{|boom|}}");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request, context);
-        EntityUtils.consume(response.getEntity());
-
-        Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+        this.httpclient.execute(target, request, context, response -> {
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         final HttpRequest reqWrapper = context.getRequest();
 
@@ -248,9 +250,11 @@ public class TestClientRequestExecution extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet("/stuff#blahblah");
         final HttpClientContext context = HttpClientContext.create();
 
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context);
-        Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, httpget, context, response -> {
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         final HttpRequest request = context.getRequest();
         Assert.assertEquals("/stuff", request.getRequestUri());
@@ -273,9 +277,10 @@ public class TestClientRequestExecution extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet(uri);
         final HttpClientContext context = HttpClientContext.create();
 
-        final ClassicHttpResponse response = this.httpclient.execute(httpget, context);
-        Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(httpget, context, response -> {
+            Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+            return null;
+        });
 
         final HttpRequest request = context.getRequest();
         Assert.assertEquals("/stuff", request.getRequestUri());
@@ -298,16 +303,14 @@ public class TestClientRequestExecution extends LocalServerTestBase {
             for (int i = 0; i < 20; i++) {
                 final HttpGet httpget = new HttpGet("/random/1000");
 
-                executorService.schedule(new Runnable() {
+                executorService.schedule(httpget::cancel, 1, TimeUnit.MILLISECONDS);
 
-                    @Override
-                    public void run() {
-                        httpget.cancel();
-                    }
-                }, 1, TimeUnit.MILLISECONDS);
+                try {
+                    this.httpclient.execute(target, httpget, response -> {
+                        EntityUtils.consume(response.getEntity());
+                        return null;
+                    });
 
-                try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget)) {
-                    EntityUtils.consume(response.getEntity());
                 } catch (final Exception ignore) {
                 }
             }
@@ -316,16 +319,13 @@ public class TestClientRequestExecution extends LocalServerTestBase {
             for (int i = 0; i < 20; i++) {
                 final HttpGet httpget = new HttpGet("/random/1000");
 
-                executorService.schedule(new Runnable() {
+                executorService.schedule(httpget::cancel, rnd.nextInt(200), TimeUnit.MILLISECONDS);
 
-                    @Override
-                    public void run() {
-                        httpget.cancel();
-                    }
-                }, rnd.nextInt(200), TimeUnit.MILLISECONDS);
-
-                try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget)) {
-                    EntityUtils.consume(response.getEntity());
+                try {
+                    this.httpclient.execute(target, httpget, response -> {
+                        EntityUtils.consume(response.getEntity());
+                        return null;
+                    });
                 } catch (final Exception ignore) {
                 }
 
@@ -333,9 +333,10 @@ public class TestClientRequestExecution extends LocalServerTestBase {
 
             for (int i = 0; i < 5; i++) {
                 final HttpGet httpget = new HttpGet("/random/1000");
-                try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget)) {
+                this.httpclient.execute(target, httpget, response -> {
                     EntityUtils.consume(response.getEntity());
-                }
+                    return null;
+                });
             }
 
         } finally {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionReuse.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionReuse.java
index c88a506..1f9a1a0 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionReuse.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionReuse.java
@@ -32,7 +32,6 @@ import java.net.URI;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElements;
@@ -168,28 +167,36 @@ public class TestConnectionReuse extends LocalServerTestBase {
                 .build();
         final HttpHost target = start(httpproc, null);
 
-        ClassicHttpResponse response = this.httpclient.execute(target, new HttpGet("/random/2000"));
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, new HttpGet("/random/2000"), response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
-        response = this.httpclient.execute(target, new HttpGet("/random/2000"));
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, new HttpGet("/random/2000"), response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
         // Now sleep for 1.1 seconds and let the timeout do its work
         Thread.sleep(1100);
-        response = this.httpclient.execute(target, new HttpGet("/random/2000"));
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, new HttpGet("/random/2000"), response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
         // Do another request just under the 1 second limit & make
         // sure we reuse that connection.
         Thread.sleep(500);
-        response = this.httpclient.execute(target, new HttpGet("/random/2000"));
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, new HttpGet("/random/2000"), response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
     }
@@ -223,14 +230,14 @@ public class TestConnectionReuse extends LocalServerTestBase {
             try {
                 for (int i = 0; i < this.repetitions; i++) {
                     final HttpGet httpget = new HttpGet(this.requestURI);
-                    final ClassicHttpResponse response = this.httpclient.execute(
-                            this.target,
-                            httpget);
-                    if (this.forceClose) {
-                        httpget.cancel();
-                    } else {
-                        EntityUtils.consume(response.getEntity());
-                    }
+                    this.httpclient.execute(this.target, httpget, response -> {
+                        if (this.forceClose) {
+                            response.close();
+                        } else {
+                            EntityUtils.consume(response.getEntity());
+                        }
+                        return null;
+                    });
                 }
             } catch (final Exception ex) {
                 this.exception = ex;
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
index a074259..9b32edb 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
@@ -92,9 +92,11 @@ public class TestContentCodings extends LocalServerTestBase {
         final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request);
-        Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode());
-        Assert.assertNull(response.getEntity());
+        this.httpclient.execute(target, request, response -> {
+            Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode());
+            Assert.assertNull(response.getEntity());
+            return null;
+        });
     }
 
     /**
@@ -112,9 +114,11 @@ public class TestContentCodings extends LocalServerTestBase {
         final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request);
-        Assert.assertEquals("The entity text is correctly transported", entityText,
-                EntityUtils.toString(response.getEntity()));
+        this.httpclient.execute(target, request, response -> {
+            Assert.assertEquals("The entity text is correctly transported", entityText,
+                    EntityUtils.toString(response.getEntity()));
+            return null;
+        });
     }
 
     /**
@@ -132,9 +136,11 @@ public class TestContentCodings extends LocalServerTestBase {
         final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request);
-        Assert.assertEquals("The entity text is correctly transported", entityText,
-                EntityUtils.toString(response.getEntity()));
+        this.httpclient.execute(target, request, response -> {
+            Assert.assertEquals("The entity text is correctly transported", entityText,
+                    EntityUtils.toString(response.getEntity()));
+            return null;
+        });
     }
 
     /**
@@ -151,9 +157,11 @@ public class TestContentCodings extends LocalServerTestBase {
         final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request);
-        Assert.assertEquals("The entity text is correctly transported", entityText,
-                EntityUtils.toString(response.getEntity()));
+        this.httpclient.execute(target, request, response -> {
+            Assert.assertEquals("The entity text is correctly transported", entityText,
+                    EntityUtils.toString(response.getEntity()));
+            return null;
+        });
     }
 
     /**
@@ -217,12 +225,13 @@ public class TestContentCodings extends LocalServerTestBase {
         final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request);
-        final ByteArrayOutputStream out = new ByteArrayOutputStream();
-
-        response.getEntity().writeTo(out);
+        this.httpclient.execute(target, request, response -> {
+            final ByteArrayOutputStream out = new ByteArrayOutputStream();
+            response.getEntity().writeTo(out);
+            Assert.assertEquals(entityText, out.toString("utf-8"));
+            return null;
+        });
 
-        Assert.assertEquals(entityText, out.toString("utf-8"));
     }
 
     @Test
@@ -234,12 +243,12 @@ public class TestContentCodings extends LocalServerTestBase {
         final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final ClassicHttpResponse response = this.httpclient.execute(target, request);
-        final ByteArrayOutputStream out = new ByteArrayOutputStream();
-
-        response.getEntity().writeTo(out);
-
-        Assert.assertEquals(entityText, out.toString("utf-8"));
+        this.httpclient.execute(target, request, response -> {
+            final ByteArrayOutputStream out = new ByteArrayOutputStream();
+            response.getEntity().writeTo(out);
+            Assert.assertEquals(entityText, out.toString("utf-8"));
+            return out;
+        });
     }
 
     @Test
@@ -428,8 +437,8 @@ public class TestContentCodings extends LocalServerTestBase {
             try {
                 startGate.await();
                 try {
-                    final ClassicHttpResponse response = client.execute(target, request);
-                    text = EntityUtils.toString(response.getEntity());
+                    text = httpclient.execute(target, request, response ->
+                            EntityUtils.toString(response.getEntity()));
                 } catch (final Exception e) {
                     failed = true;
                 } finally {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java
index ff78c56..3302e12 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java
@@ -33,7 +33,6 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.cookie.BasicCookieStore;
 import org.apache.hc.client5.http.cookie.Cookie;
 import org.apache.hc.client5.http.cookie.CookieStore;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpStatus;
@@ -96,12 +95,12 @@ public class TestCookieVirtualHost extends LocalServerTestBase {
         context.setCookieStore(cookieStore);
 
         // First request : retrieve a domain cookie from remote server.
-        URI uri = new URI("http://app.mydomain.fr");
-        HttpGet httpRequest = new HttpGet(uri);
-        httpRequest.addHeader("X-Request", "1");
-        try (CloseableHttpResponse response1 = this.httpclient.execute(target, httpRequest, context)) {
-            EntityUtils.consume(response1.getEntity());
-        }
+        final HttpGet request1 = new HttpGet(new URI("http://app.mydomain.fr"));
+        request1.addHeader("X-Request", "1");
+        this.httpclient.execute(target, request1, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         // We should have one cookie set on domain.
         final List<Cookie> cookies = cookieStore.getCookies();
@@ -110,20 +109,20 @@ public class TestCookieVirtualHost extends LocalServerTestBase {
         Assert.assertEquals("name1", cookies.get(0).getName());
 
         // Second request : send the cookie back.
-        uri = new URI("http://app.mydomain.fr");
-        httpRequest = new HttpGet(uri);
-        httpRequest.addHeader("X-Request", "2");
-        try (CloseableHttpResponse response2 = this.httpclient.execute(target, httpRequest, context)) {
-            EntityUtils.consume(response2.getEntity());
-        }
+        final HttpGet request2 = new HttpGet(new URI("http://app.mydomain.fr"));
+        request2.addHeader("X-Request", "2");
+        this.httpclient.execute(target, request2, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         // Third request : Host header
-        uri = new URI("http://app.mydomain.fr");
-        httpRequest = new HttpGet(uri);
-        httpRequest.addHeader("X-Request", "3");
-        try (CloseableHttpResponse response3 = this.httpclient.execute(target, httpRequest, context)) {
-            EntityUtils.consume(response3.getEntity());
-        }
+        final HttpGet request3 = new HttpGet(new URI("http://app.mydomain.fr"));
+        request3.addHeader("X-Request", "3");
+        this.httpclient.execute(target, request3, context, response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestIdleConnectionEviction.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestIdleConnectionEviction.java
index 46cecd1..a364ef5 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestIdleConnectionEviction.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestIdleConnectionEviction.java
@@ -33,7 +33,6 @@ import org.apache.hc.client5.http.ClientProtocolException;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.IdleConnectionEvictor;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.util.TimeValue;
@@ -95,14 +94,19 @@ public class TestIdleConnectionEviction extends LocalServerTestBase {
             try {
                 for (int i = 0; i < this.count; i++) {
                     final HttpGet httpget = new HttpGet(this.requestUri);
-                    try (final ClassicHttpResponse response = this.httpclient.execute(this.target, httpget)) {
+                    this.httpclient.execute(this.target, httpget, response -> {
                         final int status = response.getCode();
                         if (status != 200) {
                             throw new ClientProtocolException("Unexpected status code: " + status);
                         }
                         EntityUtils.consume(response.getEntity());
-                        Thread.sleep(10);
-                    }
+                        try {
+                            Thread.sleep(10);
+                        } catch (final InterruptedException ex) {
+                            Thread.currentThread().interrupt();
+                        }
+                        return null;
+                    });
                 }
             } catch (final Exception ex) {
                 this.ex = ex;
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java
index fb929d5..456a8b2 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java
@@ -31,7 +31,6 @@ import java.net.Socket;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpException;
@@ -98,15 +97,17 @@ public class TestMalformedServerResponse {
             final HttpHost target = new HttpHost("localhost", server.getLocalPort());
             try (final CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
                 final HttpGet get1 = new HttpGet("/nostuff");
-                try (final CloseableHttpResponse response1 = httpclient.execute(target, get1)) {
-                    Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response1.getCode());
-                    EntityUtils.consume(response1.getEntity());
-                }
+                httpclient.execute(target, get1, response -> {
+                    Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode());
+                    EntityUtils.consume(response.getEntity());
+                    return null;
+                });
                 final HttpGet get2 = new HttpGet("/stuff");
-                try (final CloseableHttpResponse response2 = httpclient.execute(target, get2)) {
-                    Assert.assertEquals(HttpStatus.SC_OK, response2.getCode());
-                    EntityUtils.consume(response2.getEntity());
-                }
+                httpclient.execute(target, get2, response -> {
+                    Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+                    EntityUtils.consume(response.getEntity());
+                    return null;
+                });
             }
         }
     }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java
index a42ae48..946cb11 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java
@@ -32,7 +32,6 @@ import java.util.Locale;
 import java.util.Set;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -80,10 +79,11 @@ public class TestMinimalClientRequestExecution extends LocalServerTestBase {
         final HttpClientContext context = HttpClientContext.create();
         for (int i = 0; i < 10; i++) {
             final HttpGet request = new HttpGet("/");
-            try (final CloseableHttpResponse response = this.httpclient.execute(target, request, context)) {
+            this.httpclient.execute(target, request, context, response -> {
                 EntityUtils.consume(response.getEntity());
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            }
+                return null;
+            });
 
             final HttpRequest reqWrapper = context.getRequest();
             Assert.assertNotNull(reqWrapper);
@@ -108,10 +108,11 @@ public class TestMinimalClientRequestExecution extends LocalServerTestBase {
 
         for (int i = 0; i < 10; i++) {
             final HttpGet request = new HttpGet("/");
-            try (final CloseableHttpResponse response = this.httpclient.execute(target, request)) {
+            this.httpclient.execute(target, request, response -> {
                 EntityUtils.consume(response.getEntity());
                 Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            }
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
index 7712a7f..4163d38 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
@@ -48,7 +48,6 @@ import org.apache.hc.client5.testing.classic.RedirectingDecorator;
 import org.apache.hc.client5.testing.redirect.Redirect;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHeaders;
@@ -80,19 +79,18 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpClientContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("/oldlocation/100");
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_MULTIPLE_CHOICES, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/100").build(),
-                    reqWrapper.getUri());
-
-            final RedirectLocations redirects = context.getRedirectLocations();
-            Assert.assertNotNull(redirects);
-            Assert.assertEquals(0, redirects.size());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/100").build(),
+                reqWrapper.getUri());
+
+        final RedirectLocations redirects = context.getRedirectLocations();
+        Assert.assertNotNull(redirects);
+        Assert.assertEquals(0, redirects.size());
     }
 
     @Test
@@ -104,19 +102,19 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpClientContext context = HttpClientContext.create();
         final HttpGet httpget = new HttpGet("/oldlocation/100");
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_MULTIPLE_CHOICES, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/100").build(),
-                    reqWrapper.getUri());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
-            final RedirectLocations redirects = context.getRedirectLocations();
-            Assert.assertNotNull(redirects);
-            Assert.assertEquals(0, redirects.size());
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/100").build(),
+                reqWrapper.getUri());
 
-            EntityUtils.consume(response.getEntity());
-        }
+        final RedirectLocations redirects = context.getRedirectLocations();
+        Assert.assertNotNull(redirects);
+        Assert.assertEquals(0, redirects.size());
     }
 
     @Test
@@ -129,22 +127,22 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/100");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
-                    reqWrapper.getUri());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
-            final RedirectLocations redirects = context.getRedirectLocations();
-            Assert.assertNotNull(redirects);
-            Assert.assertEquals(1, redirects.size());
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
+                reqWrapper.getUri());
 
-            final URI redirect = new URIBuilder().setHttpHost(target).setPath("/random/100").build();
-            Assert.assertTrue(redirects.contains(redirect));
+        final RedirectLocations redirects = context.getRedirectLocations();
+        Assert.assertNotNull(redirects);
+        Assert.assertEquals(1, redirects.size());
 
-            EntityUtils.consume(response.getEntity());
-        }
+        final URI redirect = new URIBuilder().setHttpHost(target).setPath("/random/100").build();
+        Assert.assertTrue(redirects.contains(redirect));
     }
 
     @Test
@@ -157,15 +155,16 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/50");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/50").build(),
-                    reqWrapper.getUri());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
+
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/50").build(),
+                reqWrapper.getUri());
+
     }
 
     @Test
@@ -184,14 +183,15 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/100");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
+        this.httpclient.execute(target, httpget, context, response -> {
             final HttpRequest reqWrapper = context.getRequest();
 
             Assert.assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getCode());
             Assert.assertEquals("/oldlocation/100", reqWrapper.getRequestUri());
 
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
     }
 
     @Test
@@ -204,15 +204,15 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/123");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/123").build(),
-                    reqWrapper.getUri());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
+
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/123").build(),
+                reqWrapper.getUri());
     }
 
     @Test
@@ -228,19 +228,19 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/stuff");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/stuff").build(),
-                    reqWrapper.getUri());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
-            final RedirectLocations redirects = context.getRedirectLocations();
-            Assert.assertNotNull(redirects);
-            Assert.assertEquals(0, redirects.size());
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/stuff").build(),
+                reqWrapper.getUri());
 
-            EntityUtils.consume(response.getEntity());
-        }
+        final RedirectLocations redirects = context.getRedirectLocations();
+        Assert.assertNotNull(redirects);
+        Assert.assertEquals(0, redirects.size());
     }
 
     @Test
@@ -256,19 +256,19 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/stuff");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_USE_PROXY, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/stuff").build(),
-                    reqWrapper.getUri());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
-            final RedirectLocations redirects = context.getRedirectLocations();
-            Assert.assertNotNull(redirects);
-            Assert.assertEquals(0, redirects.size());
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/oldlocation/stuff").build(),
+                reqWrapper.getUri());
 
-            EntityUtils.consume(response.getEntity());
-        }
+        final RedirectLocations redirects = context.getRedirectLocations();
+        Assert.assertNotNull(redirects);
+        Assert.assertEquals(0, redirects.size());
     }
 
     @Test
@@ -281,15 +281,15 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/123");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/123").build(),
-                    reqWrapper.getUri());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
+
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/123").build(),
+                reqWrapper.getUri());
     }
 
     @Test
@@ -307,7 +307,7 @@ public class TestRedirects extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet("/circular-oldlocation/123");
         httpget.setConfig(config);
         final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
-                this.httpclient.execute(target, httpget));
+                this.httpclient.execute(target, httpget, response -> null));
         Assert.assertTrue(exception.getCause() instanceof RedirectException);
     }
 
@@ -325,7 +325,7 @@ public class TestRedirects extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet("/circular-oldlocation/123");
         httpget.setConfig(config);
         final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
-                this.httpclient.execute(target, httpget));
+                this.httpclient.execute(target, httpget, response -> null));
         Assert.assertTrue(exception.getCause() instanceof CircularRedirectException);
     }
 
@@ -340,17 +340,16 @@ public class TestRedirects extends LocalServerTestBase {
         final HttpPost httppost = new HttpPost("/oldlocation/stuff");
         httppost.setEntity(new StringEntity("stuff"));
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httppost, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httppost, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/echo/stuff").build(),
-                    reqWrapper.getUri());
-            Assert.assertEquals("GET", reqWrapper.getMethod());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/echo/stuff").build(),
+                reqWrapper.getUri());
+        Assert.assertEquals("GET", reqWrapper.getMethod());
     }
 
     @Test
@@ -369,15 +368,15 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/stuff");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
-                    reqWrapper.getUri());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
+
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
+                reqWrapper.getUri());
     }
 
     @Test
@@ -397,16 +396,15 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/random/oldlocation");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
-                    reqWrapper.getUri());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
+                reqWrapper.getUri());
     }
 
     @Test
@@ -425,7 +423,7 @@ public class TestRedirects extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet("/oldlocation");
 
         final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
-                this.httpclient.execute(target, httpget));
+                this.httpclient.execute(target, httpget, response -> null));
         MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(HttpException.class));
     }
 
@@ -445,7 +443,7 @@ public class TestRedirects extends LocalServerTestBase {
         final HttpGet httpget = new HttpGet("/oldlocation");
 
         final ClientProtocolException exception = Assert.assertThrows(ClientProtocolException.class, () ->
-                this.httpclient.execute(target, httpget));
+                this.httpclient.execute(target, httpget, response -> null));
         MatcherAssert.assertThat(exception.getCause(), CoreMatchers.instanceOf(ProtocolException.class));
     }
 
@@ -467,18 +465,18 @@ public class TestRedirects extends LocalServerTestBase {
         context.setCookieStore(cookieStore);
         final HttpGet httpget = new HttpGet("/oldlocation/100");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
-                    reqWrapper.getUri());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
-            final Header[] headers = reqWrapper.getHeaders("Cookie");
-            Assert.assertEquals("There can only be one (cookie)", 1, headers.length);
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
+                reqWrapper.getUri());
 
-            EntityUtils.consume(response.getEntity());
-        }
+        final Header[] headers = reqWrapper.getHeaders("Cookie");
+        Assert.assertEquals("There can only be one (cookie)", 1, headers.length);
     }
 
     @Test
@@ -493,18 +491,18 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/100");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
-                    reqWrapper.getUri());
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
 
-            final Header header = reqWrapper.getFirstHeader(HttpHeaders.USER_AGENT);
-            Assert.assertEquals("my-test-client", header.getValue());
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
+                reqWrapper.getUri());
 
-            EntityUtils.consume(response.getEntity());
-        }
+        final Header header = reqWrapper.getFirstHeader(HttpHeaders.USER_AGENT);
+        Assert.assertEquals("my-test-client", header.getValue());
     }
 
     @Test
@@ -538,15 +536,15 @@ public class TestRedirects extends LocalServerTestBase {
 
         final HttpGet httpget = new HttpGet("/oldlocation/100");
 
-        try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget, context)) {
-            final HttpRequest reqWrapper = context.getRequest();
-
+        this.httpclient.execute(target, httpget, context, response -> {
             Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
-            Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
-                    reqWrapper.getUri());
-
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
+        final HttpRequest reqWrapper = context.getRequest();
+
+        Assert.assertEquals(new URIBuilder().setHttpHost(target).setPath("/random/100").build(),
+                reqWrapper.getUri());
 
         MatcherAssert.assertThat(values.poll(), CoreMatchers.equalTo("gzip, x-gzip, deflate"));
         MatcherAssert.assertThat(values.poll(), CoreMatchers.equalTo("gzip, x-gzip, deflate"));
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java
index 1a516b1..dc1604d 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java
@@ -168,10 +168,11 @@ public class TestSPNegoScheme extends LocalServerTestBase {
 
         final String s = "/path";
         final HttpGet httpget = new HttpGet(s);
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget);
-        EntityUtils.consume(response.getEntity());
-
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+        this.httpclient.execute(target, httpget, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
     }
 
     /**
@@ -199,10 +200,12 @@ public class TestSPNegoScheme extends LocalServerTestBase {
 
         final String s = "/path";
         final HttpGet httpget = new HttpGet(s);
-        final ClassicHttpResponse response = this.httpclient.execute(target, httpget);
-        EntityUtils.consume(response.getEntity());
+        this.httpclient.execute(target, httpget, response -> {
+            EntityUtils.consume(response.getEntity());
+            Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
+            return null;
+        });
 
-        Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode());
     }
 
 }
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java
index 1cf5a27..d8a8d14 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java
@@ -161,16 +161,15 @@ public class TestStatefulConnManagement extends LocalServerTestBase {
                 this.context.setAttribute("user", this.uid);
                 for (int r = 0; r < this.requestCount; r++) {
                     final HttpGet httpget = new HttpGet("/");
-                    final ClassicHttpResponse response = this.httpclient.execute(
-                            this.target,
-                            httpget,
-                            this.context);
+                    this.httpclient.execute(this.target, httpget, this.context, response -> {
+                        EntityUtils.consume(response.getEntity());
+                        return null;
+                    });
                     this.count++;
 
                     final EndpointDetails endpointDetails = this.context.getEndpointDetails();
                     final String connuid = Integer.toHexString(System.identityHashCode(endpointDetails));
                     this.context.setAttribute("r" + r, connuid);
-                    EntityUtils.consume(response.getEntity());
                 }
 
             } catch (final Exception ex) {
@@ -202,9 +201,10 @@ public class TestStatefulConnManagement extends LocalServerTestBase {
         // Bottom of the pool : a *keep alive* connection to Route 1.
         final HttpContext context1 = new BasicHttpContext();
         context1.setAttribute("user", "stuff");
-        final ClassicHttpResponse response1 = this.httpclient.execute(
-                target, new HttpGet("/"), context1);
-        EntityUtils.consume(response1.getEntity());
+        this.httpclient.execute(target, new HttpGet("/"), context1, response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         // The ConnPoolByRoute now has 1 free connection, out of 2 max
         // The ConnPoolByRoute has one RouteSpcfcPool, that has one free connection
@@ -215,9 +215,10 @@ public class TestStatefulConnManagement extends LocalServerTestBase {
         // Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
         // Send it to another route. Must be a keepalive.
         final HttpContext context2 = new BasicHttpContext();
-        final ClassicHttpResponse response2 = this.httpclient.execute(
-                new HttpHost("127.0.0.1", this.server.getPort()), new HttpGet("/"), context2);
-        EntityUtils.consume(response2.getEntity());
+        this.httpclient.execute(new HttpHost("127.0.0.1", this.server.getPort()), new HttpGet("/"), context2, response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
         // ConnPoolByRoute now has 2 free connexions, out of its 2 max.
         // The [localhost][stuff] RouteSpcfcPool is the same as earlier
         // And there is a [127.0.0.1][null] pool with 1 free connection
@@ -230,13 +231,14 @@ public class TestStatefulConnManagement extends LocalServerTestBase {
         // The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
         // When this happens, the RouteSpecificPool becomes empty.
         final HttpContext context3 = new BasicHttpContext();
-        final ClassicHttpResponse response3 = this.httpclient.execute(
-                target, new HttpGet("/"), context3);
+        this.httpclient.execute(target, new HttpGet("/"), context3, response -> {
+            EntityUtils.consume(response.getEntity());
+            return null;
+        });
 
         // If the ConnPoolByRoute did not behave coherently with the RouteSpecificPool
         // this may fail. Ex : if the ConnPool discared the route pool because it was empty,
         // but still used it to build the request3 connection.
-        EntityUtils.consume(response3.getEntity());
 
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java
index 58241d3..28938e7 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java
@@ -30,7 +30,6 @@ import org.apache.hc.client5.http.auth.AuthSchemeFactory;
 import org.apache.hc.client5.http.auth.StandardAuthScheme;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
 import org.apache.hc.client5.http.impl.win.WinHttpClients;
 import org.apache.hc.client5.http.impl.win.WindowsNegotiateSchemeGetTokenFail;
@@ -71,9 +70,10 @@ public class TestWindowsNegotiateScheme extends LocalServerTestBase {
 
         final HttpHost target = start();
         final HttpGet httpGet = new HttpGet("/");
-        try (final CloseableHttpResponse response = customClient.execute(target, httpGet)) {
+        customClient.execute(target, httpGet, response -> {
             EntityUtils.consume(response.getEntity());
-        }
+            return null;
+        });
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java
index 55ab2fd..ca9d35b 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java
@@ -27,10 +27,15 @@
 
 package org.apache.hc.client5.http.examples;
 
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * This example demonstrates how to abort an HTTP method before its normal completion.
@@ -41,14 +46,17 @@ public class ClientAbortMethod {
         try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
             final HttpGet httpget = new HttpGet("http://httpbin.org/get");
 
+            final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
+            // Cancel the request after once second
+            executorService.schedule(httpget::cancel, 1, TimeUnit.SECONDS);
+
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
-            try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
+            httpclient.execute(httpget, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                // Do not feel like reading the response body
-                // Call cancel on the request object
-                httpget.cancel();
-            }
+                System.out.println(httpget + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java
index f8c681c..0ed2683 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java
@@ -29,10 +29,10 @@ package org.apache.hc.client5.http.examples;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.auth.CredentialsProviderBuilder;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * A simple example that uses HttpClient to execute an HTTP request against
@@ -49,11 +49,12 @@ public class ClientAuthentication {
             final HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd");
 
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
-            try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
+            httpclient.execute(httpget, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-            }
+                System.out.println(httpget + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java
index 9117d33..b51c50e 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java
@@ -31,11 +31,11 @@ import java.io.FileInputStream;
 
 import org.apache.hc.client5.http.classic.methods.HttpPost;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.io.entity.InputStreamEntity;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * Example how to use unbuffered chunk-encoded POST request.
@@ -63,11 +63,12 @@ public class ClientChunkEncodedPost {
             httppost.setEntity(reqEntity);
 
             System.out.println("Executing request " + httppost.getMethod() + " " + httppost.getUri());
-            try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
+            httpclient.execute(httppost, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-            }
+                System.out.println(httppost + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java
index 5c900af..a3c608d 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java
@@ -50,7 +50,6 @@ import org.apache.hc.client5.http.cookie.CookieStore;
 import org.apache.hc.client5.http.cookie.StandardCookieSpec;
 import org.apache.hc.client5.http.impl.auth.CredentialsProviderBuilder;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
@@ -81,6 +80,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicLineParser;
 import org.apache.hc.core5.http.message.LineParser;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.ssl.TLS;
 import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
 import org.apache.hc.core5.pool.PoolReusePolicy;
@@ -238,29 +238,24 @@ public class ClientConfiguration {
             context.setCredentialsProvider(credentialsProvider);
 
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
-            try (final CloseableHttpResponse response = httpclient.execute(httpget, context)) {
+            httpclient.execute(httpget, context, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-
-                // Once the request has been executed the local context can
-                // be used to examine updated state and various objects affected
-                // by the request execution.
-
-                // Last executed request
-                context.getRequest();
-                // Execution route
-                context.getHttpRoute();
-                // Auth exchanges
-                context.getAuthExchanges();
-                // Cookie origin
-                context.getCookieOrigin();
-                // Cookie spec used
-                context.getCookieSpec();
-                // User security token
-                context.getUserToken();
-
-            }
+                System.out.println(httpget + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
+            // Last executed request
+            context.getRequest();
+            // Execution route
+            context.getHttpRoute();
+            // Auth exchanges
+            context.getAuthExchanges();
+            // Cookie origin
+            context.getCookieOrigin();
+            // Cookie spec used
+            context.getCookieSpec();
+            // User security token
+            context.getUserToken();
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionConfig.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionConfig.java
index bcbd209..a72d6af 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionConfig.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionConfig.java
@@ -29,7 +29,6 @@ package org.apache.hc.client5.http.examples;
 import org.apache.hc.client5.http.config.ConnectionConfig;
 import org.apache.hc.client5.http.config.TlsConfig;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
@@ -92,10 +91,12 @@ public class ClientConnectionConfig {
                         .setPath("/headers")
                         .build();
                 System.out.println("Executing request " + request);
-                try (CloseableHttpResponse response = httpclient.execute(request)) {
+                httpclient.execute(request, response -> {
+                    System.out.println("----------------------------------------");
                     System.out.println(request + "->" + new StatusLine(response));
                     EntityUtils.consume(response.getEntity());
-                }
+                    return null;
+                });
             }
         }
     }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java
deleted file mode 100644
index 648160b..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.hc.client5.http.examples;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.hc.client5.http.classic.methods.HttpGet;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
-import org.apache.hc.client5.http.impl.classic.HttpClients;
-import org.apache.hc.core5.http.HttpEntity;
-
-/**
- * This example demonstrates the recommended way of using API to make sure
- * the underlying connection gets released back to the connection manager.
- */
-public class ClientConnectionRelease {
-
-    public final static void main(final String[] args) throws Exception {
-        try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
-            final HttpGet httpget = new HttpGet("http://httpbin.org/get");
-
-            System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
-            try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
-                System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-
-                // Get hold of the response entity
-                final HttpEntity entity = response.getEntity();
-
-                // If the response does not enclose an entity, there is no need
-                // to bother about connection release
-                if (entity != null) {
-                    try (final InputStream inStream = entity.getContent()) {
-                        inStream.read();
-                        // do something useful with the response
-                    } catch (final IOException ex) {
-                        // In case of an IOException the connection will be released
-                        // back to the connection manager automatically
-                        throw ex;
-                    }
-                }
-            }
-        }
-    }
-
-}
-
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java
index 8ef79df..a7eefb2 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java
@@ -34,10 +34,10 @@ import org.apache.hc.client5.http.cookie.BasicCookieStore;
 import org.apache.hc.client5.http.cookie.Cookie;
 import org.apache.hc.client5.http.cookie.CookieStore;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * This example demonstrates the use of a local HTTP context populated with
@@ -59,15 +59,16 @@ public class ClientCustomContext {
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
 
             // Pass local context as a parameter
-            try (final CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
+            httpclient.execute(httpget, localContext, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
+                System.out.println(httpget + "->" + new StatusLine(response));
                 final List<Cookie> cookies = cookieStore.getCookies();
                 for (int i = 0; i < cookies.size(); i++) {
                     System.out.println("Local cookie: " + cookies.get(i));
                 }
                 EntityUtils.consume(response.getEntity());
-            }
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java
index b1e53d6..37be073 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java
@@ -29,10 +29,9 @@ package org.apache.hc.client5.http.examples;
 import java.net.URL;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
-import org.apache.hc.client5.http.cookie.StandardCookieSpec;
 import org.apache.hc.client5.http.cookie.CookieSpecFactory;
+import org.apache.hc.client5.http.cookie.StandardCookieSpec;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.cookie.RFC6265CookieSpecFactory;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
@@ -44,6 +43,7 @@ import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.ssl.SSLContexts;
 
 /**
@@ -81,11 +81,12 @@ public class ClientCustomPublicSuffixList {
 
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
 
-            try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
+            httpclient.execute(httpget, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-            }
+                System.out.println(httpget + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomSSL.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomSSL.java
index 88382d3..18f6568 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomSSL.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomSSL.java
@@ -34,7 +34,6 @@ import javax.net.ssl.SSLSession;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.config.TlsConfig;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.io.HttpClientConnectionManager;
@@ -42,6 +41,7 @@ import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.ssl.TLS;
 import org.apache.hc.core5.ssl.SSLContexts;
 import org.apache.hc.core5.util.Timeout;
@@ -80,17 +80,17 @@ public class ClientCustomSSL {
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
 
             final HttpClientContext clientContext = HttpClientContext.create();
-            try (CloseableHttpResponse response = httpclient.execute(httpget, clientContext)) {
+            httpclient.execute(httpget, clientContext, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-
+                System.out.println(httpget + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
                 final SSLSession sslSession = clientContext.getSSLSession();
                 if (sslSession != null) {
                     System.out.println("SSL protocol " + sslSession.getProtocol());
                     System.out.println("SSL cipher suite " + sslSession.getCipherSuite());
                 }
-            }
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java
index 338a52a..847ceeb 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java
@@ -28,10 +28,10 @@ package org.apache.hc.client5.http.examples;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.pool.PoolStats;
 import org.apache.hc.core5.util.TimeValue;
 
@@ -61,11 +61,12 @@ public class ClientEvictExpiredConnections {
 
                 System.out.println("Executing request " + request.getMethod() + " " + request.getRequestUri());
 
-                try (final CloseableHttpResponse response = httpclient.execute(request)) {
+                httpclient.execute(request, response -> {
                     System.out.println("----------------------------------------");
-                    System.out.println(response.getCode() + " " + response.getReasonPhrase());
+                    System.out.println(request + "->" + new StatusLine(response));
                     EntityUtils.consume(response.getEntity());
-                }
+                    return null;
+                });
             }
 
             final PoolStats stats1 = cm.getTotalStats();
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java
index 9cf66ce..85e8185 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java
@@ -30,10 +30,10 @@ package org.apache.hc.client5.http.examples;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * How to send a request via proxy.
@@ -57,11 +57,12 @@ public class ClientExecuteProxy {
             System.out.println("Executing request " + request.getMethod() + " " + request.getUri() +
                     " via " + proxy);
 
-            try (final CloseableHttpResponse response = httpclient.execute(target, request)) {
+            httpclient.execute(request, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-            }
+                System.out.println(request + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java
index 93bbca7..4471404 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java
@@ -34,15 +34,16 @@ import java.net.Socket;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.Registry;
 import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.io.SocketConfig;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.TimeValue;
 
@@ -57,24 +58,27 @@ public class ClientExecuteSOCKS {
         final Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
                 .register("http", new MyConnectionSocketFactory())
                 .build();
-        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg);
+        final InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234);
+        final PoolingHttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
+                .setDefaultSocketConfig(SocketConfig.custom()
+                        .setSocksProxyAddress(socksaddr)
+                        .build())
+                .build();
         try (final CloseableHttpClient httpclient = HttpClients.custom()
                 .setConnectionManager(cm)
                 .build()) {
-            final InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234);
-            final HttpClientContext context = HttpClientContext.create();
-            context.setAttribute("socks.address", socksaddr);
 
             final HttpHost target = new HttpHost("http", "httpbin.org", 80);
             final HttpGet request = new HttpGet("/get");
 
             System.out.println("Executing request " + request.getMethod() + " " + request.getUri() +
                     " via SOCKS proxy " + socksaddr);
-            try (final CloseableHttpResponse response = httpclient.execute(target, request, context)) {
+            httpclient.execute(target, request, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-            }
+                System.out.println(request + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java
index cf3d737..0a580ad 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java
@@ -33,10 +33,8 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.cookie.BasicCookieStore;
 import org.apache.hc.client5.http.cookie.Cookie;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
 
@@ -52,11 +50,10 @@ public class ClientFormLogin {
                 .setDefaultCookieStore(cookieStore)
                 .build()) {
             final HttpGet httpget = new HttpGet("https://someportal/");
-            try (final CloseableHttpResponse response1 = httpclient.execute(httpget)) {
-                final HttpEntity entity = response1.getEntity();
-
-                System.out.println("Login form get: " + response1.getCode() + " " + response1.getReasonPhrase());
-                EntityUtils.consume(entity);
+            httpclient.execute(httpget, response -> {
+                System.out.println("----------------------------------------");
+                System.out.println("Login form get: " + response.getCode() + " " + response.getReasonPhrase());
+                EntityUtils.consume(response.getEntity());
 
                 System.out.println("Initial set of cookies:");
                 final List<Cookie> cookies = cookieStore.getCookies();
@@ -67,18 +64,18 @@ public class ClientFormLogin {
                         System.out.println("- " + cookies.get(i));
                     }
                 }
-            }
+                return null;
+            });
 
             final ClassicHttpRequest login = ClassicRequestBuilder.post()
                     .setUri(new URI("https://someportal/"))
                     .addParameter("IDToken1", "username")
                     .addParameter("IDToken2", "password")
                     .build();
-            try (final CloseableHttpResponse response2 = httpclient.execute(login)) {
-                final HttpEntity entity = response2.getEntity();
-
-                System.out.println("Login form get: " + response2.getCode() + " " + response2.getReasonPhrase());
-                EntityUtils.consume(entity);
+            httpclient.execute(httpget, response -> {
+                System.out.println("----------------------------------------");
+                System.out.println("Login form get: " + response.getCode() + " " + response.getReasonPhrase());
+                EntityUtils.consume(response.getEntity());
 
                 System.out.println("Post logon cookies:");
                 final List<Cookie> cookies = cookieStore.getCookies();
@@ -89,7 +86,8 @@ public class ClientFormLogin {
                         System.out.println("- " + cookies.get(i));
                     }
                 }
-            }
+                return null;
+            });
         }
     }
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java
index 61514b0..3a5c2e6 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java
@@ -33,7 +33,6 @@ import java.util.concurrent.atomic.AtomicLong;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.ChainElement;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentType;
@@ -46,6 +45,7 @@ import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.protocol.HttpContext;
 
 /**
@@ -92,11 +92,12 @@ public class ClientInterceptors {
 
                 System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
 
-                try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
+                httpclient.execute(httpget, response -> {
                     System.out.println("----------------------------------------");
-                    System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                    System.out.println(EntityUtils.toString(response.getEntity()));
-                }
+                    System.out.println(httpget + "->" + new StatusLine(response));
+                    EntityUtils.consume(response.getEntity());
+                    return null;
+                });
             }
         }
     }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java
index ba26684..057a875 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java
@@ -28,7 +28,6 @@ package org.apache.hc.client5.http.examples;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
 import org.apache.hc.core5.http.HttpEntity;
@@ -103,7 +102,7 @@ public class ClientMultiThreadedExecution {
         public void run() {
             try {
                 System.out.println(id + " - about to get something from " + httpget.getUri());
-                try (CloseableHttpResponse response = httpClient.execute(httpget, context)) {
+                this.httpClient.execute(httpget, response -> {
                     System.out.println(id + " - get executed");
                     // get the response body as an array of bytes
                     final HttpEntity entity = response.getEntity();
@@ -111,7 +110,8 @@ public class ClientMultiThreadedExecution {
                         final byte[] bytes = EntityUtils.toByteArray(entity);
                         System.out.println(id + " - " + bytes.length + " bytes read");
                     }
-                }
+                    return null;
+                });
             } catch (final Exception e) {
                 System.out.println(id + " - error: " + e);
             }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java
index 4d5a8f3..79f382f 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java
@@ -33,11 +33,11 @@ import org.apache.hc.client5.http.entity.mime.FileBody;
 import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
 import org.apache.hc.client5.http.entity.mime.StringBody;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * Example how to use multipart/form encoded POST request.
@@ -65,15 +65,16 @@ public class ClientMultipartFormPost {
             httppost.setEntity(reqEntity);
 
             System.out.println("executing request " + httppost);
-            try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
+            httpclient.execute(httppost, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response);
+                System.out.println(httppost + "->" + new StatusLine(response));
                 final HttpEntity resEntity = response.getEntity();
                 if (resEntity != null) {
                     System.out.println("Response content length: " + resEntity.getContentLength());
                 }
-                EntityUtils.consume(resEntity);
-            }
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java
index 7b71f82..8799912 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java
@@ -30,11 +30,11 @@ import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.auth.BasicScheme;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * An example of how HttpClient can be customized to authenticate
@@ -63,11 +63,12 @@ public class ClientPreemptiveBasicAuthentication {
 
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
             for (int i = 0; i < 3; i++) {
-                try (final CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
+                httpclient.execute(httpget, localContext, response -> {
                     System.out.println("----------------------------------------");
-                    System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                    System.out.println(EntityUtils.toString(response.getEntity()));
-                }
+                    System.out.println(httpget + "->" + new StatusLine(response));
+                    EntityUtils.consume(response.getEntity());
+                    return null;
+                });
             }
         }
     }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java
index 0dbc463..69b3a04 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java
@@ -33,11 +33,11 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.auth.CredentialsProviderBuilder;
 import org.apache.hc.client5.http.impl.auth.DigestScheme;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * An example of how HttpClient can authenticate multiple requests
@@ -61,9 +61,9 @@ public class ClientPreemptiveDigestAuthentication {
 
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
             for (int i = 0; i < 3; i++) {
-                try (final CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) {
+                httpclient.execute(httpget, localContext, response -> {
                     System.out.println("----------------------------------------");
-                    System.out.println(response.getCode() + " " + response.getReasonPhrase());
+                    System.out.println(httpget + "->" + new StatusLine(response));
                     EntityUtils.consume(response.getEntity());
 
                     final AuthExchange authExchange = localContext.getAuthExchange(target);
@@ -75,7 +75,8 @@ public class ClientPreemptiveDigestAuthentication {
                                     "; count: " + digestScheme.getNounceCount());
                         }
                     }
-                }
+                    return null;
+                });
             }
         }
     }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java
index d237029..108495b 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java
@@ -32,10 +32,10 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.impl.auth.CredentialsProviderBuilder;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
  * A simple example that uses HttpClient to execute an HTTP request
@@ -63,11 +63,12 @@ public class ClientProxyAuthentication {
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri() +
                     " via " + proxy);
 
-            try (final CloseableHttpResponse response = httpclient.execute(target, httpget)) {
+            httpclient.execute(httpget, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                System.out.println(EntityUtils.toString(response.getEntity()));
-            }
+                System.out.println(httpget + "->" + new StatusLine(response));
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
         }
     }
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java
similarity index 67%
copy from httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java
copy to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java
index 55ab2fd..ad7c455 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java
@@ -29,28 +29,43 @@ package org.apache.hc.client5.http.examples;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
 
 /**
- * This example demonstrates how to abort an HTTP method before its normal completion.
+ * This example demonstrates the recommended way of processing the HTTP response and releasing
+ * associated resources.
  */
-public class ClientAbortMethod {
+public class ClientResponseProcessing {
 
     public static void main(final String[] args) throws Exception {
         try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
             final HttpGet httpget = new HttpGet("http://httpbin.org/get");
 
             System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
-            try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
+
+            final Result result = httpclient.execute(httpget, response -> {
                 System.out.println("----------------------------------------");
-                System.out.println(response.getCode() + " " + response.getReasonPhrase());
-                // Do not feel like reading the response body
-                // Call cancel on the request object
-                httpget.cancel();
-            }
+                System.out.println(httpget + "->" + new StatusLine(response));
+                // Process response message and convert it into a value object
+                return new Result(response.getCode(), EntityUtils.toString(response.getEntity()));
+            });
+            System.out.println(result);
         }
     }
 
+    static class Result {
+
+        final int status;
+        final String content;
+
+        Result(final int status, final String content) {
+            this.status = status;
+            this.content = content;
+        }
+
+    }
+
 }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java
deleted file mode 100644
index d9a4406..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.hc.client5.http.examples;
-
-import org.apache.hc.client5.http.ClientProtocolException;
-import org.apache.hc.client5.http.classic.methods.HttpGet;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.HttpClients;
-import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.ParseException;
-import org.apache.hc.core5.http.io.HttpClientResponseHandler;
-import org.apache.hc.core5.http.io.entity.EntityUtils;
-
-/**
- * This example demonstrates the use of the {@link HttpClientResponseHandler} to simplify
- * the process of processing the HTTP response and releasing associated resources.
- */
-public class ClientWithResponseHandler {
-
-    public static void main(final String[] args) throws Exception {
-        try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
-            final HttpGet httpget = new HttpGet("http://httpbin.org/get");
-
-            System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
-
-            // Create a custom response handler
-            final HttpClientResponseHandler<String> responseHandler = response -> {
-                final int status = response.getCode();
-                if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_REDIRECTION) {
-                    final HttpEntity entity = response.getEntity();
-                    try {
-                        return entity != null ? EntityUtils.toString(entity) : null;
-                    } catch (final ParseException ex) {
-                        throw new ClientProtocolException(ex);
-                    }
-                } else {
-                    throw new ClientProtocolException("Unexpected response status: " + status);
-                }
-            };
-            final String responseBody = httpclient.execute(httpget, responseHandler);
-            System.out.println("----------------------------------------");
-            System.out.println(responseBody);
-        }
-    }
-
-}
-
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpClientBuilderInterceptors.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpClientBuilderInterceptors.java
index bbce383..bee13b1 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpClientBuilderInterceptors.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpClientBuilderInterceptors.java
@@ -32,11 +32,12 @@ import org.apache.hc.client5.http.classic.methods.HttpPost;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
 import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.io.CloseMode;
 import org.junit.After;
 import org.junit.Assert;
@@ -84,7 +85,10 @@ public class TestHttpClientBuilderInterceptors {
     @Test
     public void testAddExecInterceptorLastShouldBeExecuted() throws IOException, HttpException {
         final ClassicHttpRequest request = new HttpPost(uri);
-        final ClassicHttpResponse response = httpClient.execute(request);
+        final HttpResponse response = httpClient.execute(request, httpResponse -> {
+            EntityUtils.consume(httpResponse.getEntity());
+            return httpResponse;
+        });
         Assert.assertEquals(200, response.getCode());
         final Header testFilterHeader = response.getHeader("X-Test-Interceptor");
         Assert.assertNotNull(testFilterHeader);