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/09 21:50:20 UTC

[httpcomponents-client] branch master updated (58386f8 -> 6cce828)

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.


    from 58386f8  Add @OverRide.
     new 3dd3795  Use Java 8 Time APIs for date / time operations in the HTTP cache tests
     new 6cce828  Updated examples and unit tests to make use of lambda expressions for response message processing

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/http/cache/TestHttpCacheEntry.java  |  27 +-
 .../hc/client5/http/impl/cache/HttpTestUtils.java  |  47 +--
 .../http/impl/cache/TestBasicHttpCache.java        |  13 +-
 .../http/impl/cache/TestCacheUpdateHandler.java    |  87 ++---
 .../http/impl/cache/TestCacheValidityPolicy.java   | 101 +++--
 .../TestCachedResponseSuitabilityChecker.java      | 104 +++---
 .../http/impl/cache/TestCachingExecChain.java      | 263 ++++++-------
 .../impl/cache/TestConditionalRequestBuilder.java  |  42 +--
 .../cache/TestDefaultAsyncCacheInvalidator.java    |  58 +--
 .../impl/cache/TestDefaultCacheInvalidator.java    |  56 +--
 .../impl/cache/TestHttpCacheJiraNumber1147.java    |   8 +-
 .../impl/cache/TestProtocolAllowedBehavior.java    |   8 +-
 .../http/impl/cache/TestProtocolDeviations.java    |   8 +-
 .../impl/cache/TestProtocolRecommendations.java    | 127 ++++---
 .../http/impl/cache/TestProtocolRequirements.java  | 415 ++++++++++-----------
 .../http/impl/cache/TestRFC5861Compliance.java     |  72 ++--
 .../http/impl/cache/TestResponseCachingPolicy.java | 132 ++++---
 .../impl/cache/TestResponseProtocolCompliance.java |   4 +-
 .../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 +-
 54 files changed, 1336 insertions(+), 1411 deletions(-)
 delete mode 100644 httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java
 copy httpclient5/src/test/java/org/apache/hc/client5/http/examples/{ClientAbortMethod.java => ClientResponseProcessing.java} (67%)
 delete mode 100644 httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java

[httpcomponents-client] 01/02: Use Java 8 Time APIs for date / time operations in the HTTP cache tests

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 3dd37952bce9cc9bef78e248958f628e21d96b75
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Nov 8 14:21:31 2021 +0100

    Use Java 8 Time APIs for date / time operations in the HTTP cache tests
---
 .../hc/client5/http/cache/TestHttpCacheEntry.java  |  27 +-
 .../hc/client5/http/impl/cache/HttpTestUtils.java  |  47 +--
 .../http/impl/cache/TestBasicHttpCache.java        |  13 +-
 .../http/impl/cache/TestCacheUpdateHandler.java    |  87 ++---
 .../http/impl/cache/TestCacheValidityPolicy.java   | 101 +++--
 .../TestCachedResponseSuitabilityChecker.java      | 104 +++---
 .../http/impl/cache/TestCachingExecChain.java      | 263 ++++++-------
 .../impl/cache/TestConditionalRequestBuilder.java  |  42 +--
 .../cache/TestDefaultAsyncCacheInvalidator.java    |  58 +--
 .../impl/cache/TestDefaultCacheInvalidator.java    |  56 +--
 .../impl/cache/TestHttpCacheJiraNumber1147.java    |   8 +-
 .../impl/cache/TestProtocolAllowedBehavior.java    |   8 +-
 .../http/impl/cache/TestProtocolDeviations.java    |   8 +-
 .../impl/cache/TestProtocolRecommendations.java    | 127 ++++---
 .../http/impl/cache/TestProtocolRequirements.java  | 415 ++++++++++-----------
 .../http/impl/cache/TestRFC5861Compliance.java     |  72 ++--
 .../http/impl/cache/TestResponseCachingPolicy.java | 132 ++++---
 .../impl/cache/TestResponseProtocolCompliance.java |   4 +-
 18 files changed, 782 insertions(+), 790 deletions(-)

diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
index 7401b9a..bb4b57f 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
@@ -36,6 +36,8 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 
+import java.time.Instant;
+import java.time.temporal.ChronoField;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -49,22 +51,23 @@ import org.junit.Test;
 
 public class TestHttpCacheEntry {
 
-    private Date now;
-    private Date elevenSecondsAgo;
-    private Date nineSecondsAgo;
+    private Instant now;
+    private Instant elevenSecondsAgo;
+    private Instant nineSecondsAgo;
     private Resource mockResource;
     private HttpCacheEntry entry;
 
     @Before
     public void setUp() {
-        now = new Date();
-        elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
-        nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
+        now = Instant.now();
+        elevenSecondsAgo = now.minusSeconds(11);
+        nineSecondsAgo = now.minusSeconds(9);
         mockResource = mock(Resource.class);
     }
 
     private HttpCacheEntry makeEntry(final Header[] headers) {
-        return new HttpCacheEntry(elevenSecondsAgo, nineSecondsAgo, HttpStatus.SC_OK, headers, mockResource);
+        return new HttpCacheEntry(DateUtils.toDate(elevenSecondsAgo), DateUtils.toDate(nineSecondsAgo),
+                HttpStatus.SC_OK, headers, mockResource);
     }
 
     @Test
@@ -197,7 +200,7 @@ public class TestHttpCacheEntry {
     public void canGetOriginalHeaders() {
         final Header[] headers = {
                 new BasicHeader("Server", "MockServer/1.0"),
-                new BasicHeader("Date", DateUtils.formatDate(now))
+                new BasicHeader("Date", DateUtils.formatStandardDate(now))
         };
         entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, headers, mockResource);
         final Header[] result = entry.getHeaders();
@@ -282,15 +285,13 @@ public class TestHttpCacheEntry {
 
     @Test
     public void testValidDateHeaderIsParsed() {
-        final long nowMs = System.currentTimeMillis();
-        // round down to nearest second to make comparison easier
-        final Date date = new Date(nowMs - (nowMs % 1000L));
-        final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatDate(date)) };
+        final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
+        final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(date)) };
         entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
                                    headers, mockResource);
         final Date dateHeaderValue = entry.getDate();
         assertNotNull(dateHeaderValue);
-        assertEquals(date.getTime(), dateHeaderValue.getTime());
+        assertEquals(DateUtils.toDate(date), dateHeaderValue);
     }
 
     @Test
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
index 3136b03..d263af5 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
@@ -27,6 +27,8 @@
 package org.apache.hc.client5.http.impl.cache;
 
 import java.io.InputStream;
+import java.time.Duration;
+import java.time.Instant;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -237,50 +239,51 @@ public class HttpTestUtils {
         return new ByteArrayEntity(getRandomBytes(nbytes), null);
     }
 
-    public static HttpCacheEntry makeCacheEntry(final Date requestDate, final Date responseDate) {
-        final Date when = new Date((responseDate.getTime() + requestDate.getTime()) / 2);
+    public static HttpCacheEntry makeCacheEntry(final Instant requestDate, final Instant responseDate) {
+        final Duration diff = Duration.between(requestDate, responseDate);
+        final Instant when = requestDate.plusMillis(diff.toMillis() / 2);
         return makeCacheEntry(requestDate, responseDate, getStockHeaders(when));
     }
 
-    public static Header[] getStockHeaders(final Date when) {
-        final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(when)),
+    public static Header[] getStockHeaders(final Instant when) {
+        return new Header[] {
+                new BasicHeader("Date", DateUtils.formatStandardDate(when)),
                 new BasicHeader("Server", "MockServer/1.0")
         };
-        return headers;
     }
 
-    public static HttpCacheEntry makeCacheEntry(final Date requestDate,
-            final Date responseDate, final Header... headers) {
+    public static HttpCacheEntry makeCacheEntry(final Instant requestDate,
+                                                final Instant responseDate, final Header... headers) {
         final byte[] bytes = getRandomBytes(128);
         return makeCacheEntry(requestDate, responseDate, headers, bytes);
     }
 
-    public static HttpCacheEntry makeCacheEntry(final Date requestDate,
-            final Date responseDate, final Header[] headers, final byte[] bytes) {
-        return makeCacheEntry(requestDate, responseDate, headers, bytes,
-                null);
+    public static HttpCacheEntry makeCacheEntry(final Instant requestDate,
+                                                final Instant responseDate, final Header[] headers, final byte[] bytes) {
+        return makeCacheEntry(requestDate, responseDate, headers, bytes, null);
     }
 
     public static HttpCacheEntry makeCacheEntry(final Map<String,String> variantMap) {
-        final Date now = new Date();
+        final Instant now = Instant.now();
         return makeCacheEntry(now, now, getStockHeaders(now),
                 getRandomBytes(128), variantMap);
     }
 
-    public static HttpCacheEntry makeCacheEntry(final Date requestDate,
-            final Date responseDate, final Header[] headers, final byte[] bytes,
+    public static HttpCacheEntry makeCacheEntry(final Instant requestDate,
+            final Instant responseDate, final Header[] headers, final byte[] bytes,
             final Map<String,String> variantMap) {
-        return new HttpCacheEntry(requestDate, responseDate, HttpStatus.SC_OK, headers, new HeapResource(bytes), variantMap);
+        return new HttpCacheEntry(DateUtils.toDate(requestDate), DateUtils.toDate(responseDate),
+                HttpStatus.SC_OK, headers, new HeapResource(bytes), variantMap);
     }
 
     public static HttpCacheEntry makeCacheEntry(final Header[] headers, final byte[] bytes) {
-        final Date now = new Date();
+        final Instant now = Instant.now();
         return makeCacheEntry(now, now, headers, bytes);
     }
 
     public static HttpCacheEntry makeCacheEntry(final byte[] bytes) {
-        return makeCacheEntry(getStockHeaders(new Date()), bytes);
+        final Instant now = Instant.now();
+        return makeCacheEntry(getStockHeaders(now), bytes);
     }
 
     public static HttpCacheEntry makeCacheEntry(final Header... headers) {
@@ -288,7 +291,7 @@ public class HttpTestUtils {
     }
 
     public static HttpCacheEntry makeCacheEntry() {
-        final Date now = new Date();
+        final Instant now = Instant.now();
         return makeCacheEntry(now, now);
     }
 
@@ -319,16 +322,16 @@ public class HttpTestUtils {
 
     public static ClassicHttpResponse make200Response() {
         final ClassicHttpResponse out = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        out.setHeader("Date", DateUtils.formatDate(new Date()));
+        out.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         out.setHeader("Server", "MockOrigin/1.0");
         out.setHeader("Content-Length", "128");
         out.setEntity(makeBody(128));
         return out;
     }
 
-    public static final ClassicHttpResponse make200Response(final Date date, final String cacheControl) {
+    public static final ClassicHttpResponse make200Response(final Instant date, final String cacheControl) {
         final ClassicHttpResponse response = HttpTestUtils.make200Response();
-        response.setHeader("Date", DateUtils.formatDate(date));
+        response.setHeader("Date", DateUtils.formatStandardDate(date));
         response.setHeader("Cache-Control",cacheControl);
         response.setHeader("Etag","\"etag\"");
         return response;
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestBasicHttpCache.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestBasicHttpCache.java
index 9e3e892..7c0cc25 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestBasicHttpCache.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestBasicHttpCache.java
@@ -32,6 +32,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 
+import java.time.Instant;
 import java.util.Date;
 import java.util.Map;
 
@@ -134,7 +135,7 @@ public class TestBasicHttpCache {
         final String key = CacheKeyGenerator.INSTANCE.generateKey(host, new HttpGet("/bar"));
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(new Date())),
+           new BasicHeader("Date", DateUtils.formatStandardDate(Instant.now())),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -155,7 +156,7 @@ public class TestBasicHttpCache {
         final String key = CacheKeyGenerator.INSTANCE.generateKey(host, new HttpGet("/bar"));
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(new Date())),
+           new BasicHeader("Date", DateUtils.formatStandardDate(Instant.now())),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -224,7 +225,7 @@ public class TestBasicHttpCache {
 
         final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
         final HttpResponse origResponse = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
-        origResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        origResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         origResponse.setHeader("Cache-Control", "max-age=3600, public");
         origResponse.setHeader("ETag", "\"etag\"");
         origResponse.setHeader("Vary", "Accept-Encoding");
@@ -246,7 +247,7 @@ public class TestBasicHttpCache {
 
         final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
         final HttpResponse origResponse = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
-        origResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        origResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         origResponse.setHeader("Cache-Control", "max-age=3600, public");
         origResponse.setHeader("ETag", "\"etag\"");
         origResponse.setHeader("Vary", "Accept-Encoding");
@@ -278,7 +279,7 @@ public class TestBasicHttpCache {
         req1.setHeader("Accept-Encoding", "gzip");
 
         final HttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "max-age=3600, public");
         resp1.setHeader("ETag", "\"etag1\"");
         resp1.setHeader("Vary", "Accept-Encoding");
@@ -289,7 +290,7 @@ public class TestBasicHttpCache {
         req2.setHeader("Accept-Encoding", "identity");
 
         final HttpResponse resp2 = HttpTestUtils.make200Response();
-        resp2.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp2.setHeader("Cache-Control", "max-age=3600, public");
         resp2.setHeader("ETag", "\"etag2\"");
         resp2.setHeader("Vary", "Accept-Encoding");
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
index fb8f9dd..4d28e04 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
@@ -31,6 +31,7 @@ import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.time.Instant;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -48,28 +49,28 @@ import org.junit.Test;
 
 public class TestCacheUpdateHandler {
 
-    private Date requestDate;
-    private Date responseDate;
+    private Instant requestDate;
+    private Instant responseDate;
 
     private CacheUpdateHandler impl;
     private HttpCacheEntry entry;
-    private Date now;
-    private Date oneSecondAgo;
-    private Date twoSecondsAgo;
-    private Date eightSecondsAgo;
-    private Date tenSecondsAgo;
+    private Instant now;
+    private Instant oneSecondAgo;
+    private Instant twoSecondsAgo;
+    private Instant eightSecondsAgo;
+    private Instant tenSecondsAgo;
     private HttpResponse response;
 
     @Before
     public void setUp() throws Exception {
-        requestDate = new Date(System.currentTimeMillis() - 1000);
-        responseDate = new Date();
+        requestDate = Instant.now().minusSeconds(1);
+        responseDate = Instant.now();
 
-        now = new Date();
-        oneSecondAgo = new Date(now.getTime() - 1000L);
-        twoSecondsAgo = new Date(now.getTime() - 2000L);
-        eightSecondsAgo = new Date(now.getTime() - 8000L);
-        tenSecondsAgo = new Date(now.getTime() - 10000L);
+        now = Instant.now();
+        oneSecondAgo = now.minusSeconds(1);
+        twoSecondsAgo = now.minusSeconds(2);
+        eightSecondsAgo = now.minusSeconds(8);
+        tenSecondsAgo = now.minusSeconds(10);
 
         response = new BasicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
 
@@ -81,14 +82,14 @@ public class TestCacheUpdateHandler {
             throws IOException {
         entry = HttpTestUtils.makeCacheEntry();
         final HttpCacheEntry newEntry = impl.updateCacheEntry(null, entry,
-                requestDate, responseDate, response);
+                DateUtils.toDate(requestDate), DateUtils.toDate(responseDate), response);
         assertNotSame(newEntry, entry);
     }
 
     @Test
     public void testHeadersAreMergedCorrectly() throws IOException {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(responseDate)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(responseDate)),
                 new BasicHeader("ETag", "\"etag\"")};
         entry = HttpTestUtils.makeCacheEntry(headers);
         response.setHeaders();
@@ -96,29 +97,29 @@ public class TestCacheUpdateHandler {
         final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
                 new Date(), new Date(), response);
 
-        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(responseDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatStandardDate(responseDate)));
         MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
     }
 
     @Test
     public void testNewerHeadersReplaceExistingHeaders() throws IOException {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(requestDate)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
                 new BasicHeader("Cache-Control", "private"),
                 new BasicHeader("ETag", "\"etag\""),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(requestDate)),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(requestDate)),
                 new BasicHeader("Cache-Control", "max-age=0"),};
         entry = HttpTestUtils.makeCacheEntry(headers);
 
-        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
+        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatStandardDate(responseDate)),
                 new BasicHeader("Cache-Control", "public"));
 
         final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
                 new Date(), new Date(), response);
 
-        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(requestDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatStandardDate(requestDate)));
         MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
-        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatDate(responseDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatStandardDate(responseDate)));
         MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Cache-Control", "public"));
     }
 
@@ -126,19 +127,19 @@ public class TestCacheUpdateHandler {
     public void testNewHeadersAreAddedByMerge() throws IOException {
 
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(requestDate)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
                 new BasicHeader("ETag", "\"etag\"")};
 
         entry = HttpTestUtils.makeCacheEntry(headers);
-        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
+        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatStandardDate(responseDate)),
                 new BasicHeader("Cache-Control", "public"));
 
         final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
                 new Date(), new Date(), response);
 
-        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(requestDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Date", DateUtils.formatStandardDate(requestDate)));
         MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("ETag", "\"etag\""));
-        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatDate(responseDate)));
+        MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Last-Modified", DateUtils.formatStandardDate(responseDate)));
         MatcherAssert. assertThat(updatedEntry, ContainsHeaderMatcher.contains("Cache-Control", "public"));
     }
 
@@ -146,15 +147,15 @@ public class TestCacheUpdateHandler {
     public void oldHeadersRetainedIfResponseOlderThanEntry()
             throws Exception {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(oneSecondAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
                 new BasicHeader("ETag", "\"new-etag\"")
         };
         entry = HttpTestUtils.makeCacheEntry(twoSecondsAgo, now, headers);
-        response.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        response.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         response.setHeader("ETag", "\"old-etag\"");
         final HttpCacheEntry result = impl.updateCacheEntry("A", entry, new Date(),
                 new Date(), response);
-        MatcherAssert. assertThat(result, ContainsHeaderMatcher.contains("Date", DateUtils.formatDate(oneSecondAgo)));
+        MatcherAssert. assertThat(result, ContainsHeaderMatcher.contains("Date", DateUtils.formatStandardDate(oneSecondAgo)));
         MatcherAssert. assertThat(result, ContainsHeaderMatcher.contains("ETag", "\"new-etag\""));
     }
 
@@ -163,10 +164,10 @@ public class TestCacheUpdateHandler {
             throws IOException {
         entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo);
         final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
-                twoSecondsAgo, oneSecondAgo, response);
+                DateUtils.toDate(twoSecondsAgo), DateUtils.toDate(oneSecondAgo), response);
 
-        assertEquals(twoSecondsAgo, updated.getRequestDate());
-        assertEquals(oneSecondAgo, updated.getResponseDate());
+        assertEquals(DateUtils.toDate(twoSecondsAgo), updated.getRequestDate());
+        assertEquals(DateUtils.toDate(oneSecondAgo), updated.getResponseDate());
     }
 
     @Test
@@ -174,13 +175,13 @@ public class TestCacheUpdateHandler {
         final Header[] headers = {
                 new BasicHeader("Warning", "110 fred \"Response is stale\""),
                 new BasicHeader("ETag", "\"old\""),
-                new BasicHeader("Date", DateUtils.formatDate(eightSecondsAgo))
+                new BasicHeader("Date", DateUtils.formatStandardDate(eightSecondsAgo))
         };
         entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo, headers);
         response.setHeader("ETag", "\"new\"");
-        response.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        response.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
         final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
-                twoSecondsAgo, oneSecondAgo, response);
+                DateUtils.toDate(twoSecondsAgo), DateUtils.toDate(oneSecondAgo), response);
 
         assertEquals(0, updated.getHeaders("Warning").length);
     }
@@ -193,9 +194,9 @@ public class TestCacheUpdateHandler {
         };
         entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo, headers);
         response.setHeader("ETag", "\"new\"");
-        response.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        response.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
         final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
-                twoSecondsAgo, oneSecondAgo, response);
+                DateUtils.toDate(twoSecondsAgo), DateUtils.toDate(oneSecondAgo), response);
 
         assertEquals("\"new\"", updated.getFirstHeader("ETag").getValue());
     }
@@ -204,13 +205,13 @@ public class TestCacheUpdateHandler {
     public void entryIsStillUpdatedByResponseWithMalformedDate() throws Exception {
         final Header[] headers = {
                 new BasicHeader("ETag", "\"old\""),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo))
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo))
         };
         entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo, headers);
         response.setHeader("ETag", "\"new\"");
         response.setHeader("Date", "bad-date");
         final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
-                twoSecondsAgo, oneSecondAgo, response);
+                DateUtils.toDate(twoSecondsAgo), DateUtils.toDate(oneSecondAgo), response);
 
         assertEquals("\"new\"", updated.getFirstHeader("ETag").getValue());
     }
@@ -249,12 +250,12 @@ public class TestCacheUpdateHandler {
     @Test
     public void testContentEncodingHeaderIsNotUpdatedByMerge() throws IOException {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(requestDate)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
                 new BasicHeader("ETag", "\"etag\""),
                 new BasicHeader("Content-Encoding", "identity")};
 
         entry = HttpTestUtils.makeCacheEntry(headers);
-        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
+        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatStandardDate(responseDate)),
                 new BasicHeader("Cache-Control", "public"),
                 new BasicHeader("Content-Encoding", "gzip"));
 
@@ -269,12 +270,12 @@ public class TestCacheUpdateHandler {
     @Test
     public void testContentLengthIsNotAddedWhenTransferEncodingIsPresent() throws IOException {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(requestDate)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
                 new BasicHeader("ETag", "\"etag\""),
                 new BasicHeader("Transfer-Encoding", "chunked")};
 
         entry = HttpTestUtils.makeCacheEntry(headers);
-        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
+        response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatStandardDate(responseDate)),
                 new BasicHeader("Cache-Control", "public"),
                 new BasicHeader("Content-Length", "0"));
 
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheValidityPolicy.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheValidityPolicy.java
index 2389644..4548b1c 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheValidityPolicy.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheValidityPolicy.java
@@ -31,6 +31,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+import java.time.Instant;
 import java.util.Date;
 
 import org.apache.hc.client5.http.cache.HttpCacheEntry;
@@ -47,20 +48,20 @@ import org.junit.Test;
 public class TestCacheValidityPolicy {
 
     private CacheValidityPolicy impl;
-    private Date now;
-    private Date oneSecondAgo;
-    private Date sixSecondsAgo;
-    private Date tenSecondsAgo;
-    private Date elevenSecondsAgo;
+    private Instant now;
+    private Instant oneSecondAgo;
+    private Instant sixSecondsAgo;
+    private Instant tenSecondsAgo;
+    private Instant elevenSecondsAgo;
 
     @Before
     public void setUp() {
         impl = new CacheValidityPolicy();
-        now = new Date();
-        oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
+        now = Instant.now();
+        oneSecondAgo = now.minusSeconds(1);
+        sixSecondsAgo = now.minusSeconds(6);
+        tenSecondsAgo = now.minusSeconds(10);
+        elevenSecondsAgo = now.minusSeconds(11);
     }
 
     @Test
@@ -74,8 +75,7 @@ public class TestCacheValidityPolicy {
 
     @Test
     public void testApparentAgeIsResponseReceivedTimeLessDateHeader() {
-        final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
-                .formatDate(tenSecondsAgo)) };
+        final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)) };
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, sixSecondsAgo, headers);
         assertEquals(TimeValue.ofSeconds(4), impl.getApparentAge(entry));
@@ -83,8 +83,7 @@ public class TestCacheValidityPolicy {
 
     @Test
     public void testNegativeApparentAgeIsBroughtUpToZero() {
-        final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
-                .formatDate(sixSecondsAgo)) };
+        final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo)) };
         final HttpCacheEntry entry  = HttpTestUtils.makeCacheEntry(now, tenSecondsAgo, headers);
         assertEquals(TimeValue.ofSeconds(0), impl.getApparentAge(entry));
     }
@@ -141,7 +140,7 @@ public class TestCacheValidityPolicy {
     @Test
     public void testResidentTimeSecondsIsTimeSinceResponseTime() {
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, sixSecondsAgo);
-        assertEquals(TimeValue.ofSeconds(6), impl.getResidentTime(entry, now));
+        assertEquals(TimeValue.ofSeconds(6), impl.getResidentTime(entry, DateUtils.toDate(now)));
     }
 
     @Test
@@ -190,8 +189,8 @@ public class TestCacheValidityPolicy {
     @Test
     public void testFreshnessLifetimeIsMaxAgeEvenIfExpiresIsPresent() {
         final Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10"),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
+                new BasicHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo)) };
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertEquals(TimeValue.ofSeconds(10), impl.getFreshnessLifetime(entry));
@@ -200,8 +199,8 @@ public class TestCacheValidityPolicy {
     @Test
     public void testFreshnessLifetimeIsSMaxAgeEvenIfExpiresIsPresent() {
         final Header[] headers = new Header[] { new BasicHeader("Cache-Control", "s-maxage=10"),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
+                new BasicHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo)) };
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertEquals(TimeValue.ofSeconds(10), impl.getFreshnessLifetime(entry));
@@ -210,8 +209,8 @@ public class TestCacheValidityPolicy {
     @Test
     public void testFreshnessLifetimeIsFromExpiresHeaderIfNoMaxAge() {
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
-                new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
+                new BasicHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo)) };
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertEquals(TimeValue.ofSeconds(4), impl.getFreshnessLifetime(entry));
@@ -220,8 +219,8 @@ public class TestCacheValidityPolicy {
     @Test
     public void testHeuristicFreshnessLifetime() {
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(oneSecondAgo)),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(elevenSecondsAgo))
+                new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(elevenSecondsAgo))
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertEquals(TimeValue.ofSeconds(1), impl.getHeuristicFreshnessLifetime(entry, 0.1f, TimeValue.ZERO_MILLISECONDS));
@@ -237,8 +236,8 @@ public class TestCacheValidityPolicy {
     @Test
     public void testHeuristicFreshnessLifetimeIsNonNegative() {
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(elevenSecondsAgo)),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(oneSecondAgo))
+                new BasicHeader("Date", DateUtils.formatStandardDate(elevenSecondsAgo)),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(oneSecondAgo))
         };
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
@@ -252,7 +251,7 @@ public class TestCacheValidityPolicy {
             @Override
             public TimeValue getCurrentAge(final HttpCacheEntry e, final Date d) {
                 assertSame(entry, e);
-                assertEquals(now, d);
+                assertEquals(DateUtils.toDate(now), d);
                 return TimeValue.ofSeconds(6);
             }
             @Override
@@ -261,7 +260,7 @@ public class TestCacheValidityPolicy {
                 return TimeValue.ofSeconds(10);
             }
         };
-        assertTrue(impl.isResponseFresh(entry, now));
+        assertTrue(impl.isResponseFresh(entry, DateUtils.toDate(now)));
     }
 
     @Test
@@ -270,7 +269,7 @@ public class TestCacheValidityPolicy {
         impl = new CacheValidityPolicy() {
             @Override
             public TimeValue getCurrentAge(final HttpCacheEntry e, final Date d) {
-                assertEquals(now, d);
+                assertEquals(DateUtils.toDate(now), d);
                 assertSame(entry, e);
                 return TimeValue.ofSeconds(6);
             }
@@ -280,7 +279,7 @@ public class TestCacheValidityPolicy {
                 return TimeValue.ofSeconds(6);
             }
         };
-        assertFalse(impl.isResponseFresh(entry, now));
+        assertFalse(impl.isResponseFresh(entry, DateUtils.toDate(now)));
     }
 
     @Test
@@ -289,7 +288,7 @@ public class TestCacheValidityPolicy {
         impl = new CacheValidityPolicy() {
             @Override
             public TimeValue getCurrentAge(final HttpCacheEntry e, final Date d) {
-                assertEquals(now, d);
+                assertEquals(DateUtils.toDate(now), d);
                 assertSame(entry, e);
                 return TimeValue.ofSeconds(10);
             }
@@ -299,13 +298,13 @@ public class TestCacheValidityPolicy {
                 return TimeValue.ofSeconds(6);
             }
         };
-        assertFalse(impl.isResponseFresh(entry, now));
+        assertFalse(impl.isResponseFresh(entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testCacheEntryIsRevalidatableIfHeadersIncludeETag() {
         final Header[] headers = {
-                new BasicHeader("Expires", DateUtils.formatDate(new Date())),
+                new BasicHeader("Expires", DateUtils.formatStandardDate(Instant.now())),
                 new BasicHeader("ETag", "somevalue")};
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertTrue(impl.isRevalidatable(entry));
@@ -314,8 +313,8 @@ public class TestCacheValidityPolicy {
     @Test
     public void testCacheEntryIsRevalidatableIfHeadersIncludeLastModifiedDate() {
         final Header[] headers = {
-                new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())) };
+                new BasicHeader("Expires", DateUtils.formatStandardDate(Instant.now())),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now())) };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertTrue(impl.isRevalidatable(entry));
     }
@@ -323,7 +322,7 @@ public class TestCacheValidityPolicy {
     @Test
     public void testCacheEntryIsNotRevalidatableIfNoAppropriateHeaders() {
         final Header[] headers =  {
-                new BasicHeader("Expires", DateUtils.formatDate(new Date())),
+                new BasicHeader("Expires", DateUtils.formatStandardDate(Instant.now())),
                 new BasicHeader("Cache-Control", "public") };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
         assertFalse(impl.isRevalidatable(entry));
@@ -416,47 +415,47 @@ public class TestCacheValidityPolicy {
     @Test
     public void testMayReturnStaleIfErrorInResponseIsTrueWithinStaleness(){
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5, stale-if-error=15")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
         final HttpRequest req = new BasicHttpRequest("GET","/");
-        assertTrue(impl.mayReturnStaleIfError(req, entry, now));
+        assertTrue(impl.mayReturnStaleIfError(req, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMayReturnStaleIfErrorInRequestIsTrueWithinStaleness(){
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
         final HttpRequest req = new BasicHttpRequest("GET","/");
         req.setHeader("Cache-Control","stale-if-error=15");
-        assertTrue(impl.mayReturnStaleIfError(req, entry, now));
+        assertTrue(impl.mayReturnStaleIfError(req, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMayNotReturnStaleIfErrorInResponseAndAfterResponseWindow(){
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5, stale-if-error=1")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
         final HttpRequest req = new BasicHttpRequest("GET","/");
-        assertFalse(impl.mayReturnStaleIfError(req, entry, now));
+        assertFalse(impl.mayReturnStaleIfError(req, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMayNotReturnStaleIfErrorInResponseAndAfterRequestWindow(){
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
         final HttpRequest req = new BasicHttpRequest("GET","/");
         req.setHeader("Cache-Control","stale-if-error=1");
-        assertFalse(impl.mayReturnStaleIfError(req, entry, now));
+        assertFalse(impl.mayReturnStaleIfError(req, entry, DateUtils.toDate(now)));
     }
 
     @Test
@@ -464,40 +463,40 @@ public class TestCacheValidityPolicy {
         final Header[] headers = new Header[] { new BasicHeader("Cache-control", "public") };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
 
-        assertFalse(impl.mayReturnStaleWhileRevalidating(entry, now));
+        assertFalse(impl.mayReturnStaleWhileRevalidating(entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMayReturnStaleWhileRevalidatingIsTrueWhenWithinStaleness() {
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5, stale-while-revalidate=15")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
 
-        assertTrue(impl.mayReturnStaleWhileRevalidating(entry, now));
+        assertTrue(impl.mayReturnStaleWhileRevalidating(entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMayReturnStaleWhileRevalidatingIsFalseWhenPastStaleness() {
-        final Date twentyFiveSecondsAgo = new Date(now.getTime() - 25 * 1000L);
+        final Instant twentyFiveSecondsAgo = now.minusSeconds(25);
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(twentyFiveSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(twentyFiveSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5, stale-while-revalidate=15")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
 
-        assertFalse(impl.mayReturnStaleWhileRevalidating(entry, now));
+        assertFalse(impl.mayReturnStaleWhileRevalidating(entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMayReturnStaleWhileRevalidatingIsFalseWhenDirectiveEmpty() {
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5, stale-while-revalidate=")
         };
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
 
-        assertFalse(impl.mayReturnStaleWhileRevalidating(entry, now));
+        assertFalse(impl.mayReturnStaleWhileRevalidating(entry, DateUtils.toDate(now)));
     }
 }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedResponseSuitabilityChecker.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedResponseSuitabilityChecker.java
index 5640156..48151ee 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedResponseSuitabilityChecker.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedResponseSuitabilityChecker.java
@@ -26,7 +26,7 @@
  */
 package org.apache.hc.client5.http.impl.cache;
 
-import java.util.Date;
+import java.time.Instant;
 
 import org.apache.hc.client5.http.cache.HttpCacheEntry;
 import org.apache.hc.client5.http.utils.DateUtils;
@@ -42,10 +42,10 @@ import org.junit.Test;
 
 public class TestCachedResponseSuitabilityChecker {
 
-    private Date now;
-    private Date elevenSecondsAgo;
-    private Date tenSecondsAgo;
-    private Date nineSecondsAgo;
+    private Instant now;
+    private Instant elevenSecondsAgo;
+    private Instant tenSecondsAgo;
+    private Instant nineSecondsAgo;
 
     private HttpHost host;
     private HttpRequest request;
@@ -54,10 +54,10 @@ public class TestCachedResponseSuitabilityChecker {
 
     @Before
     public void setUp() {
-        now = new Date();
-        elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
-        tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
+        now = Instant.now();
+        elevenSecondsAgo = now.minusSeconds(11);
+        tenSecondsAgo = now.minusSeconds(10);
+        nineSecondsAgo = now.minusSeconds(9);
 
         host = new HttpHost("foo.example.com");
         request = new BasicHttpRequest("GET", "/foo");
@@ -73,118 +73,118 @@ public class TestCachedResponseSuitabilityChecker {
     @Test
     public void testNotSuitableIfContentLengthHeaderIsWrong() {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","1")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableIfCacheEntryIsFresh() {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableIfCacheEntryIsNotFresh() {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableIfRequestHasNoCache() {
         request.addHeader("Cache-Control", "no-cache");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableIfAgeExceedsRequestMaxAge() {
         request.addHeader("Cache-Control", "max-age=10");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableIfFreshAndAgeIsUnderRequestMaxAge() {
         request.addHeader("Cache-Control", "max-age=15");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableIfFreshAndFreshnessLifetimeGreaterThanRequestMinFresh() {
         request.addHeader("Cache-Control", "min-fresh=10");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableIfFreshnessLifetimeLessThanRequestMinFresh() {
         request.addHeader("Cache-Control", "min-fresh=10");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=15"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableEvenIfStaleButPermittedByRequestMaxStale() {
         request.addHeader("Cache-Control", "max-stale=10");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableIfStaleButTooStaleForRequestMaxStale() {
         request.addHeader("Cache-Control", "max-stale=2");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=5"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
 
@@ -192,34 +192,34 @@ public class TestCachedResponseSuitabilityChecker {
     public void testMalformedCacheControlMaxAgeRequestHeaderCausesUnsuitableEntry() {
         request.addHeader(new BasicHeader("Cache-Control", "max-age=foo"));
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testMalformedCacheControlMinFreshRequestHeaderCausesUnsuitableEntry() {
         request.addHeader(new BasicHeader("Cache-Control", "min-fresh=foo"));
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableIfCacheEntryIsHeuristicallyFreshEnough() {
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twentyOneSecondsAgo = new Date(now.getTime() - 21 * 1000L);
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twentyOneSecondsAgo = now.minusSeconds(21);
 
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(oneSecondAgo)),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(twentyOneSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(twentyOneSecondsAgo)),
                 new BasicHeader("Content-Length", "128")
         };
 
@@ -230,13 +230,13 @@ public class TestCachedResponseSuitabilityChecker {
             .setHeuristicCoefficient(0.1f).build();
         impl = new CachedResponseSuitabilityChecker(config);
 
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableIfCacheEntryIsHeuristicallyFreshEnoughByDefault() {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Content-Length", "128")
         };
 
@@ -248,70 +248,70 @@ public class TestCachedResponseSuitabilityChecker {
             .build();
         impl = new CachedResponseSuitabilityChecker(config);
 
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableIfRequestMethodisHEAD() {
         final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = getEntry(headers);
 
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, headRequest, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, headRequest, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableIfRequestMethodIsGETAndEntryResourceIsNull() {
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = HttpTestUtils.makeHeadCacheEntry(headers);
 
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testNotSuitableForGETIfEntryDoesNotSpecifyARequestMethodOrEntity() {
         impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = HttpTestUtils.makeCacheEntryWithNoRequestMethodOrEntity(headers);
 
-        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableForGETIfEntryDoesNotSpecifyARequestMethodButContainsEntity() {
         impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = HttpTestUtils.makeCacheEntryWithNoRequestMethod(headers);
 
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
     public void testSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethodButContains204Response() {
         impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600")
         };
         entry = HttpTestUtils.make204CacheEntryWithNoRequestMethod(headers);
 
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, DateUtils.toDate(now)));
     }
 
     @Test
@@ -319,12 +319,12 @@ public class TestCachedResponseSuitabilityChecker {
         final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
         impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
         final Header[] headers = {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length","128")
         };
         entry = HttpTestUtils.makeHeadCacheEntryWithNoRequestMethod(headers);
 
-        Assert.assertTrue(impl.canCachedResponseBeUsed(host, headRequest, entry, now));
+        Assert.assertTrue(impl.canCachedResponseBeUsed(host, headRequest, entry, DateUtils.toDate(now)));
     }
 }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
index 7074989..546df59 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
@@ -32,7 +32,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
-import java.util.Date;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
 
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
@@ -128,12 +129,12 @@ public class TestCachingExecChain {
 
     @Test
     public void testOlderCacheableResponsesDoNotGoIntoCache() throws Exception {
-        final Date now = new Date();
-        final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
+        final Instant now = Instant.now();
+        final Instant fiveSecondsAgo = now.minusSeconds(5);
 
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("Etag", "\"new-etag\"");
 
@@ -141,7 +142,7 @@ public class TestCachingExecChain {
         req2.setHeader("Cache-Control", "no-cache");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("ETag", "\"old-etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(fiveSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(fiveSecondsAgo));
         resp2.setHeader("Cache-Control", "max-age=3600");
 
         final ClassicHttpRequest req3 = HttpTestUtils.makeDefaultRequest();
@@ -160,12 +161,12 @@ public class TestCachingExecChain {
 
     @Test
     public void testNewerCacheableResponsesReplaceExistingCacheEntry() throws Exception {
-        final Date now = new Date();
-        final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
+        final Instant now = Instant.now();
+        final Instant fiveSecondsAgo = now.minusSeconds(5);
 
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(fiveSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(fiveSecondsAgo));
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("Etag", "\"old-etag\"");
 
@@ -173,7 +174,7 @@ public class TestCachingExecChain {
         req2.setHeader("Cache-Control", "max-age=0");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("ETag", "\"new-etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "max-age=3600");
 
         final ClassicHttpRequest req3 = HttpTestUtils.makeDefaultRequest();
@@ -280,7 +281,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -297,7 +298,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -315,7 +316,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -327,18 +328,18 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns304ForIfModifiedSinceHeaderIfRequestServedFromCache() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(now));
         final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -349,18 +350,18 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns304ForIfModifiedSinceHeaderIf304ResponseInCache() throws Exception {
-        final Date now = new Date();
-        final Date oneHourAgo = new Date(now.getTime() - 3600 * 1000L);
-        final Date inTenMinutes = new Date(now.getTime() + 600 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
+        final Instant inTenMinutes = now.plus(10, ChronoUnit.MINUTES);
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
-        req1.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
+        req1.addHeader("If-Modified-Since", DateUtils.formatStandardDate(oneHourAgo));
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(oneHourAgo));
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make304Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-control", "max-age=600");
-        resp1.setHeader("Expires", DateUtils.formatDate(inTenMinutes));
+        resp1.setHeader("Expires", DateUtils.formatStandardDate(inTenMinutes));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -375,8 +376,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns200ForIfModifiedSinceDateIsLess() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
 
@@ -384,12 +385,12 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now()));
 
         // The variant has been modified since this date
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
 
@@ -405,8 +406,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns200ForIfModifiedSinceDateIsInvalid() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAfter = new Date(now.getTime() + 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAfter = now.plusSeconds(10);
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
 
@@ -414,12 +415,12 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now()));
 
         // invalid date (date in the future)
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAfter));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(tenSecondsAfter));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -439,7 +440,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -459,7 +460,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
         req2.addHeader("If-None-Match", "\"abc\"");
@@ -478,8 +479,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns304ForIfNoneMatchHeaderAndIfModifiedSinceIfRequestServedFromCache() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
 
@@ -487,12 +488,12 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(new Date()));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now()));
 
         req2.addHeader("If-None-Match", "*");
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -503,19 +504,19 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns200ForIfNoneMatchHeaderFailsIfModifiedSinceIgnored() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
         req2.addHeader("If-None-Match", "\"abc\"");
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(now));
         final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -527,7 +528,7 @@ public class TestCachingExecChain {
     @Test
     public void testReturns200ForOptionsFollowedByGetIfAuthorizationHeaderAndSharedCache() throws Exception {
         impl = new CachingExec(cache, null, CacheConfig.custom().setSharedCache(true).build());
-        final Date now = new Date();
+        final Instant now = Instant.now();
         final ClassicHttpRequest req1 = new HttpOptions("http://foo.example.com/");
         req1.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -535,16 +536,16 @@ public class TestCachingExecChain {
         final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
         resp1.setHeader("Content-Length", "0");
         resp1.setHeader("ETag", "\"options-etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(now));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(now));
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"get-etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "public, max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(now));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
         execute(req1);
@@ -557,8 +558,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testSetsValidatedContextIfRequestWasSuccessfullyValidated() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -567,14 +568,14 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("ETag", "\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp2.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -588,8 +589,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testSetsViaHeaderIfRequestWasSuccessfullyValidated() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -598,14 +599,14 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("ETag", "\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp2.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -620,8 +621,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testSetsModuleResponseContextIfValidationRequiredButFailed() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -630,7 +631,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5, must-revalidate");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -646,8 +647,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testSetsModuleResponseContextIfValidationFailsButNotRequired() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -656,7 +657,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -671,8 +672,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testSetViaHeaderIfValidationFailsButNotRequired() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -681,7 +682,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -697,8 +698,8 @@ public class TestCachingExecChain {
     @Test
     public void testReturns304ForIfNoneMatchPassesIfRequestServedFromOrigin() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -707,13 +708,13 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         req2.addHeader("If-None-Match", "\"etag\"");
         final ClassicHttpResponse resp2 = HttpTestUtils.make304Response();
         resp2.setHeader("ETag", "\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -729,8 +730,8 @@ public class TestCachingExecChain {
     @Test
     public void testReturns200ForIfNoneMatchFailsIfRequestServedFromOrigin() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -739,7 +740,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         req2.addHeader("If-None-Match", "\"etag\"");
@@ -747,7 +748,7 @@ public class TestCachingExecChain {
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("ETag", "\"newetag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp2.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -762,8 +763,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns304ForIfModifiedSincePassesIfRequestServedFromOrigin() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -772,15 +773,15 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(tenSecondsAgo));
         final ClassicHttpResponse resp2 = HttpTestUtils.make304Response();
         resp2.setHeader("ETag", "\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
         resp2.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -796,8 +797,8 @@ public class TestCachingExecChain {
 
     @Test
     public void testReturns200ForIfModifiedSinceFailsIfRequestServedFromOrigin() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
@@ -806,17 +807,17 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
-        req2.addHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
+        req2.addHeader("If-Modified-Since", DateUtils.formatStandardDate(tenSecondsAgo));
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("ETag", "\"newetag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -832,7 +833,7 @@ public class TestCachingExecChain {
 
     @Test
     public void testVariantMissServerIfReturns304CacheReturns200() throws Exception {
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
         req1.addHeader("Accept-Encoding", "gzip");
@@ -841,7 +842,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("Etag", "\"gzip_etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Vary", "Accept-Encoding");
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
@@ -856,7 +857,7 @@ public class TestCachingExecChain {
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("Etag", "\"deflate_etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setHeader("Cache-Control", "public, max-age=3600");
 
@@ -871,7 +872,7 @@ public class TestCachingExecChain {
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Content-Length", "128");
         resp3.setHeader("Etag", "\"gzip_etag\"");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
         resp3.setHeader("Vary", "Accept-Encoding");
         resp3.setHeader("Cache-Control", "public, max-age=3600");
 
@@ -894,7 +895,7 @@ public class TestCachingExecChain {
 
     @Test
     public void testVariantsMissServerReturns304CacheReturns304() throws Exception {
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
         req1.addHeader("Accept-Encoding", "gzip");
@@ -903,7 +904,7 @@ public class TestCachingExecChain {
         resp1.setEntity(HttpTestUtils.makeBody(128));
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("Etag", "\"gzip_etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Vary", "Accept-Encoding");
         resp1.setHeader("Cache-Control", "public, max-age=3600");
 
@@ -918,7 +919,7 @@ public class TestCachingExecChain {
         resp2.setEntity(HttpTestUtils.makeBody(128));
         resp2.setHeader("Content-Length", "128");
         resp2.setHeader("Etag", "\"deflate_etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setHeader("Cache-Control", "public, max-age=3600");
 
@@ -932,7 +933,7 @@ public class TestCachingExecChain {
 
         final ClassicHttpResponse resp4 = HttpTestUtils.make304Response();
         resp4.setHeader("Etag", "\"gzip_etag\"");
-        resp4.setHeader("Date", DateUtils.formatDate(now));
+        resp4.setHeader("Date", DateUtils.formatStandardDate(now));
         resp4.setHeader("Vary", "Accept-Encoding");
         resp4.setHeader("Cache-Control", "public, max-age=3600");
 
@@ -955,7 +956,7 @@ public class TestCachingExecChain {
 
     @Test
     public void testSocketTimeoutExceptionIsNotSilentlyCatched() throws Exception {
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
 
@@ -976,7 +977,7 @@ public class TestCachingExecChain {
                 throw new SocketTimeoutException("Read timed out");
             }
         }, 128, null));
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -996,19 +997,20 @@ public class TestCachingExecChain {
         final HttpHost host = new HttpHost("foo.example.com");
         final ClassicHttpRequest request = new HttpGet("http://foo.example.com/bar");
 
-        final Date now = new Date();
-        final Date requestSent = new Date(now.getTime() - 3 * 1000L);
-        final Date responseGenerated = new Date(now.getTime() - 2 * 1000L);
-        final Date responseReceived = new Date(now.getTime() - 1 * 1000L);
+        final Instant now = Instant.now();
+        final Instant requestSent = now.plusSeconds(3);
+        final Instant responseGenerated = now.plusSeconds(2);
+        final Instant responseReceived = now.plusSeconds(1);
 
         final ClassicHttpResponse originResponse = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES + 1));
         originResponse.setHeader("Cache-Control","public, max-age=3600");
-        originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(responseGenerated));
         originResponse.setHeader("ETag", "\"etag\"");
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, mockExecRuntime, context);
-        impl.cacheAndReturnResponse(host, request, originResponse, scope, requestSent, responseReceived);
+        impl.cacheAndReturnResponse(host, request, originResponse, scope,
+                DateUtils.toDate(requestSent), DateUtils.toDate(responseReceived));
 
         Mockito.verify(cache, Mockito.never()).createCacheEntry(
                 Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
@@ -1022,15 +1024,15 @@ public class TestCachingExecChain {
         final HttpHost host = new HttpHost("foo.example.com");
         final ClassicHttpRequest request = new HttpGet("http://foo.example.com/bar");
 
-        final Date now = new Date();
-        final Date requestSent = new Date(now.getTime() - 3 * 1000L);
-        final Date responseGenerated = new Date(now.getTime() - 2 * 1000L);
-        final Date responseReceived = new Date(now.getTime() - 1 * 1000L);
+        final Instant now = Instant.now();
+        final Instant requestSent = now.plusSeconds(3);
+        final Instant responseGenerated = now.plusSeconds(2);
+        final Instant responseReceived = now.plusSeconds(1);
 
         final ClassicHttpResponse originResponse = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES - 1));
         originResponse.setHeader("Cache-Control","public, max-age=3600");
-        originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(responseGenerated));
         originResponse.setHeader("ETag", "\"etag\"");
 
         final HttpCacheEntry httpCacheEntry = HttpTestUtils.makeCacheEntry();
@@ -1041,11 +1043,12 @@ public class TestCachingExecChain {
                 RequestEquivalent.eq(request),
                 ResponseEquivalent.eq(response),
                 Mockito.any(),
-                Mockito.eq(requestSent),
-                Mockito.eq(responseReceived))).thenReturn(httpCacheEntry);
+                Mockito.eq(DateUtils.toDate(requestSent)),
+                Mockito.eq(DateUtils.toDate(responseReceived)))).thenReturn(httpCacheEntry);
 
         final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, mockExecRuntime, context);
-        impl.cacheAndReturnResponse(host, request, originResponse, scope, requestSent, responseReceived);
+        impl.cacheAndReturnResponse(host, request, originResponse, scope,
+                DateUtils.toDate(requestSent), DateUtils.toDate(responseReceived));
 
         Mockito.verify(mockCache).createCacheEntry(
                 Mockito.any(),
@@ -1119,7 +1122,7 @@ public class TestCachingExecChain {
     @Test
     public void testCanCacheAResponseWithoutABody() throws Exception {
         final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
-        response.setHeader("Date", DateUtils.formatDate(new Date()));
+        response.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         response.setHeader("Cache-Control", "max-age=300");
         Mockito.when(mockExecChain.proceed(RequestEquivalent.eq(request), Mockito.any())).thenReturn(response);
 
@@ -1132,8 +1135,8 @@ public class TestCachingExecChain {
     @Test
     public void testNoEntityForIfNoneMatchRequestNotYetInCache() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         req1.addHeader("If-None-Match", "\"etag\"");
@@ -1141,7 +1144,7 @@ public class TestCachingExecChain {
         final ClassicHttpResponse resp1 = HttpTestUtils.make304Response();
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("ETag", "\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1154,7 +1157,7 @@ public class TestCachingExecChain {
     @Test
     public void testNotModifiedResponseUpdatesCacheEntryWhenNoEntity() throws Exception {
 
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         req1.addHeader("If-None-Match", "etag");
@@ -1163,12 +1166,12 @@ public class TestCachingExecChain {
         req2.addHeader("If-None-Match", "etag");
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make304Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
 
         final ClassicHttpResponse resp2 = HttpTestUtils.make304Response();
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
 
@@ -1188,7 +1191,7 @@ public class TestCachingExecChain {
     @Test
     public void testNotModifiedResponseWithVaryUpdatesCacheEntryWhenNoEntity() throws Exception {
 
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         req1.addHeader("If-None-Match", "etag");
@@ -1197,13 +1200,13 @@ public class TestCachingExecChain {
         req2.addHeader("If-None-Match", "etag");
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make304Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
         resp1.setHeader("Vary", "Accept-Encoding");
 
         final ClassicHttpResponse resp2 = HttpTestUtils.make304Response();
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "max-age=0");
         resp1.setHeader("Etag", "etag");
         resp1.setHeader("Vary", "Accept-Encoding");
@@ -1225,8 +1228,8 @@ public class TestCachingExecChain {
     @Test
     public void testDoesNotSend304ForNonConditionalRequest() throws Exception {
 
-        final Date now = new Date();
-        final Date inOneMinute = new Date(System.currentTimeMillis() + 60000);
+        final Instant now = Instant.now();
+        final Instant inOneMinute = now.plus(1, ChronoUnit.MINUTES);
 
         final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
         req1.addHeader("If-None-Match", "etag");
@@ -1234,17 +1237,17 @@ public class TestCachingExecChain {
         final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make304Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "public, max-age=60");
-        resp1.setHeader("Expires", DateUtils.formatDate(inOneMinute));
+        resp1.setHeader("Expires", DateUtils.formatStandardDate(inOneMinute));
         resp1.setHeader("Etag", "etag");
         resp1.setHeader("Vary", "Accept-Encoding");
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK,
             "Ok");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "public, max-age=60");
-        resp2.setHeader("Expires", DateUtils.formatDate(inOneMinute));
+        resp2.setHeader("Expires", DateUtils.formatStandardDate(inOneMinute));
         resp2.setHeader("Etag", "etag");
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setEntity(HttpTestUtils.makeBody(128));
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
index 58ca6a0..c6cb345 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
@@ -26,7 +26,7 @@
  */
 package org.apache.hc.client5.http.impl.cache;
 
-import java.util.Date;
+import java.time.Instant;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -66,7 +66,7 @@ public class TestConditionalRequestBuilder {
         basicRequest.addHeader("Accept-Encoding", "gzip");
 
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(new Date())),
+                new BasicHeader("Date", DateUtils.formatStandardDate(Instant.now())),
                 new BasicHeader("Last-Modified", lastModified) };
 
         final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
@@ -86,13 +86,13 @@ public class TestConditionalRequestBuilder {
     @Test
     public void testConditionalRequestForEntryWithLastModifiedAndEtagIncludesBothAsValidators()
             throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date twentySecondsAgo = new Date(now.getTime() - 20 * 1000L);
-        final String lmDate = DateUtils.formatDate(twentySecondsAgo);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant twentySecondsAgo = now.plusSeconds(20);
+        final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
         final String etag = "\"etag\"";
         final Header[] headers = {
-            new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+            new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
             new BasicHeader("Last-Modified", lmDate),
             new BasicHeader("ETag", etag)
         };
@@ -115,8 +115,8 @@ public class TestConditionalRequestBuilder {
         basicRequest.addHeader("Accept-Encoding", "gzip");
 
         final Header[] headers = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(new Date())),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())),
+                new BasicHeader("Date", DateUtils.formatStandardDate(Instant.now())),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now())),
                 new BasicHeader("ETag", theETag) };
 
         final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
@@ -138,13 +138,13 @@ public class TestConditionalRequestBuilder {
     @Test
     public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
         final HttpRequest basicRequest = new BasicHttpRequest("GET","/");
-        final Date now = new Date();
-        final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
+        final Instant now = Instant.now();
+        final Instant elevenSecondsAgo = now.minusSeconds(11);
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant nineSecondsAgo = now.plusSeconds(9);
 
         final Header[] cacheEntryHeaders = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("ETag", "\"etag\""),
                 new BasicHeader("Cache-Control","max-age=5, must-revalidate") };
         final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(elevenSecondsAgo, nineSecondsAgo, cacheEntryHeaders);
@@ -166,13 +166,13 @@ public class TestConditionalRequestBuilder {
     @Test
     public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
         final HttpRequest basicRequest = new BasicHttpRequest("GET", "/");
-        final Date now = new Date();
-        final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
+        final Instant now = Instant.now();
+        final Instant elevenSecondsAgo = now.minusSeconds(11);
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant nineSecondsAgo = now.plusSeconds(9);
 
         final Header[] cacheEntryHeaders = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
                 new BasicHeader("ETag", "\"etag\""),
                 new BasicHeader("Cache-Control","max-age=5, proxy-revalidate") };
         final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(elevenSecondsAgo, nineSecondsAgo, cacheEntryHeaders);
@@ -263,7 +263,7 @@ public class TestConditionalRequestBuilder {
     @Test
     public void testBuildUnconditionalRequestDoesNotUseIfUnmodifiedSince()
         throws Exception {
-        request.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date()));
+        request.addHeader("If-Unmodified-Since", DateUtils.formatStandardDate(Instant.now()));
         final HttpRequest result = impl.buildUnconditionalRequest(request);
         Assert.assertNull(result.getFirstHeader("If-Unmodified-Since"));
     }
@@ -271,7 +271,7 @@ public class TestConditionalRequestBuilder {
     @Test
     public void testBuildUnconditionalRequestDoesNotUseIfModifiedSince()
         throws Exception {
-        request.addHeader("If-Modified-Since", DateUtils.formatDate(new Date()));
+        request.addHeader("If-Modified-Since", DateUtils.formatStandardDate(Instant.now()));
         final HttpRequest result = impl.buildUnconditionalRequest(request);
         Assert.assertNull(result.getFirstHeader("If-Modified-Since"));
     }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java
index cffae63..b9633e1 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 import java.net.URI;
-import java.util.Date;
+import java.time.Instant;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -74,13 +74,13 @@ public class TestDefaultAsyncCacheInvalidator {
     @Mock
     private Cancellable cancellable;
 
-    private Date now;
-    private Date tenSecondsAgo;
+    private Instant now;
+    private Instant tenSecondsAgo;
 
     @Before
     public void setUp() {
-        now = new Date();
-        tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        now = Instant.now();
+        tenSecondsAgo = now.minusSeconds(10);
 
         when(cacheKeyResolver.resolve(ArgumentMatchers.any())).thenAnswer((Answer<String>) invocation -> {
             final URI uri = invocation.getArgument(0);
@@ -352,12 +352,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -374,12 +374,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(201);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -396,7 +396,7 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_BAD_REQUEST, "Bad Request");
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
@@ -410,12 +410,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", "http://foo.example.com/bar");
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -432,12 +432,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", "/bar");
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -454,12 +454,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://baz.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -475,12 +475,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"same-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"same-etag\"")
         });
 
@@ -496,12 +496,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        response.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(now)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(now)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -518,7 +518,7 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
@@ -535,12 +535,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.removeHeaders("ETag");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -557,12 +557,12 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag", "\"some-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
         });
 
         cacheReturnsEntryForUri(key, entry);
@@ -584,7 +584,7 @@ public class TestDefaultAsyncCacheInvalidator {
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
                 new BasicHeader("ETag", "\"old-etag\""),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
         });
 
         cacheReturnsEntryForUri(key, entry);
@@ -601,7 +601,7 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
@@ -629,7 +629,7 @@ public class TestDefaultAsyncCacheInvalidator {
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
                 new BasicHeader("ETag", "\"old-etag\""),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo))
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo))
         });
 
         cacheReturnsEntryForUri(key, entry);
@@ -646,7 +646,7 @@ public class TestDefaultAsyncCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java
index 1a07d3e..b74ff8f 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 import java.net.URI;
-import java.util.Date;
+import java.time.Instant;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -68,13 +68,13 @@ public class TestDefaultCacheInvalidator {
     @Mock
     private HttpCacheStorage mockStorage;
 
-    private Date now;
-    private Date tenSecondsAgo;
+    private Instant now;
+    private Instant tenSecondsAgo;
 
     @Before
     public void setUp() {
-        now = new Date();
-        tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        now = Instant.now();
+        tenSecondsAgo = now.minusSeconds(10);
 
         when(cacheKeyResolver.resolve(ArgumentMatchers.any())).thenAnswer((Answer<String>) invocation -> {
             final URI uri = invocation.getArgument(0);
@@ -346,12 +346,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -368,12 +368,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(201);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -390,7 +390,7 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_BAD_REQUEST, "Bad Request");
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
@@ -404,12 +404,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String cacheKey = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", "http://foo.example.com/bar");
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -426,12 +426,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String cacheKey = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", "/bar");
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -448,7 +448,7 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String cacheKey = "http://baz.example.com:80/bar";
         response.setHeader("Content-Location", cacheKey);
 
@@ -462,12 +462,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"same-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"same-etag\"")
         });
 
@@ -483,12 +483,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        response.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(now)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(now)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -505,7 +505,7 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
@@ -522,12 +522,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.removeHeaders("ETag");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
            new BasicHeader("ETag", "\"old-etag\"")
         });
 
@@ -544,12 +544,12 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag", "\"some-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
-           new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+           new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
         });
 
         when(mockStorage.getEntry(key)).thenReturn(entry);
@@ -571,7 +571,7 @@ public class TestDefaultCacheInvalidator {
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
                 new BasicHeader("ETag", "\"old-etag\""),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)),
         });
 
         when(mockStorage.getEntry(key)).thenReturn(entry);
@@ -588,7 +588,7 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
@@ -616,7 +616,7 @@ public class TestDefaultCacheInvalidator {
 
         final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(new Header[] {
                 new BasicHeader("ETag", "\"old-etag\""),
-                new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo))
+                new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo))
         });
 
         when(mockStorage.getEntry(key)).thenReturn(entry);
@@ -633,7 +633,7 @@ public class TestDefaultCacheInvalidator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.setHeader("ETag","\"new-etag\"");
-        response.setHeader("Date", DateUtils.formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         final String key = "http://foo.example.com:80/bar";
         response.setHeader("Content-Location", key);
 
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
index a07b09c..2ce2ccd 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.io.File;
-import java.util.Date;
+import java.time.Instant;
 
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.cache.CacheResponseStatus;
@@ -102,15 +102,15 @@ public class TestHttpCacheJiraNumber1147 {
         final ClassicHttpRequest get = new HttpGet("http://somehost/");
         final HttpCacheContext context = HttpCacheContext.create();
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         response.setEntity(HttpTestUtils.makeBody(128));
         response.setHeader("Content-Length", "128");
         response.setHeader("ETag", "\"etag\"");
         response.setHeader("Cache-Control", "public, max-age=3600");
-        response.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        response.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
 
         when(mockExecChain.proceed(
                 isA(ClassicHttpRequest.class),
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
index a4146f8..9cd9b7d 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
@@ -28,7 +28,7 @@ package org.apache.hc.client5.http.impl.cache;
 
 import java.io.IOException;
 import java.net.SocketTimeoutException;
-import java.util.Date;
+import java.time.Instant;
 
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.classic.ExecChain;
@@ -111,9 +111,9 @@ public class TestProtocolAllowedBehavior {
     @Test
     public void testNonSharedCacheReturnsStaleResponseWhenRevalidationFailsForProxyRevalidate() throws Exception {
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        originResponse.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         originResponse.setHeader("Cache-Control","max-age=5,proxy-revalidate");
         originResponse.setHeader("Etag","\"etag\"");
 
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
index 6b89f14..1fef0ae 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
@@ -27,7 +27,7 @@
 package org.apache.hc.client5.http.impl.cache;
 
 import java.io.IOException;
-import java.util.Date;
+import java.time.Instant;
 import java.util.Random;
 
 import org.apache.hc.client5.http.ClientProtocolException;
@@ -79,13 +79,9 @@ public class TestProtocolDeviations {
     HttpHost host;
     HttpRoute route;
     @Mock
-    HttpEntity mockEntity;
-    @Mock
     ExecRuntime mockEndpoint;
     @Mock
     ExecChain mockExecChain;
-    @Mock
-    HttpCache mockCache;
     ClassicHttpRequest request;
     HttpCacheContext context;
     ClassicHttpResponse originResponse;
@@ -125,7 +121,7 @@ public class TestProtocolDeviations {
 
     private ClassicHttpResponse make200Response() {
         final ClassicHttpResponse out = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        out.setHeader("Date", DateUtils.formatDate(new Date()));
+        out.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         out.setHeader("Server", "MockOrigin/1.0");
         out.setEntity(makeBody(128));
         return out;
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRecommendations.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRecommendations.java
index c6afcb8..fea2225 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRecommendations.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRecommendations.java
@@ -34,8 +34,9 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
 import java.util.Arrays;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
@@ -89,16 +90,14 @@ public class TestProtocolRecommendations {
     ExecChain mockExecChain;
     @Mock
     ExecRuntime mockExecRuntime;
-    @Mock
-    HttpCache mockCache;
     ClassicHttpRequest request;
     ClassicHttpResponse originResponse;
     CacheConfig config;
     CachingExec impl;
     HttpCache cache;
-    Date now;
-    Date tenSecondsAgo;
-    Date twoMinutesAgo;
+    Instant now;
+    Instant tenSecondsAgo;
+    Instant twoMinutesAgo;
 
     @Before
     public void setUp() throws Exception {
@@ -122,9 +121,9 @@ public class TestProtocolRecommendations {
         cache = new BasicHttpCache(config);
         impl = new CachingExec(cache, null, config);
 
-        now = new Date();
-        tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        twoMinutesAgo = new Date(now.getTime() - 2 * 60 * 1000L);
+        now = Instant.now();
+        tenSecondsAgo = now.minus(10, ChronoUnit.SECONDS);
+        twoMinutesAgo = now.minus(1, ChronoUnit.MINUTES);
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
     }
@@ -200,7 +199,7 @@ public class TestProtocolRecommendations {
     private void cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
             final String headerName, final String headerValue) throws Exception {
         cacheGenerated304ForValidatorShouldNotContainEntityHeader(headerName,
-                headerValue, "Last-Modified", DateUtils.formatDate(twoMinutesAgo),
+                headerValue, "Last-Modified", DateUtils.formatStandardDate(twoMinutesAgo),
                 "If-Modified-Since");
     }
 
@@ -281,7 +280,7 @@ public class TestProtocolRecommendations {
         req2.setHeader(conditionalHeader, validator);
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader(validatorHeader, validator);
 
         // cache module does not currently deal with byte ranges, but we want
@@ -309,7 +308,7 @@ public class TestProtocolRecommendations {
     @Test
     public void cacheGenerated304ForStrongDateValidatorShouldNotContainContentRange() throws Exception {
         cacheGenerated304ForStrongValidatorShouldNotContainContentRange(
-                "Last-Modified", DateUtils.formatDate(twoMinutesAgo), "If-Modified-Since");
+                "Last-Modified", DateUtils.formatStandardDate(twoMinutesAgo), "If-Modified-Since");
     }
 
     @Test
@@ -327,13 +326,13 @@ public class TestProtocolRecommendations {
     @Test
     public void cacheGenerated304ForStrongEtagValidatorShouldNotContainLastModified() throws Exception {
         cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
-                "Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+                "Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
     }
 
     @Test
     public void cacheGenerated304ForStrongDateValidatorShouldNotContainLastModified() throws Exception {
         cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
-                "Last-Modified", DateUtils.formatDate(twoMinutesAgo));
+                "Last-Modified", DateUtils.formatStandardDate(twoMinutesAgo));
     }
 
     private void shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
@@ -342,7 +341,7 @@ public class TestProtocolRecommendations {
         req.setHeader("If-None-Match", "\"etag\"");
 
         final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp.setHeader("Date", DateUtils.formatDate(now));
+        resp.setHeader("Date", DateUtils.formatStandardDate(now));
         resp.setHeader("Etag", "\"etag\"");
         resp.setHeader(entityHeader, entityHeaderValue);
 
@@ -396,7 +395,7 @@ public class TestProtocolRecommendations {
         req.setHeader("Range","bytes=0-127");
 
         final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp.setHeader("Date", DateUtils.formatDate(now));
+        resp.setHeader("Date", DateUtils.formatStandardDate(now));
         resp.setHeader("ETag", "\"etag\"");
         resp.setHeader("Content-Range", "bytes 0-127/256");
 
@@ -410,7 +409,7 @@ public class TestProtocolRecommendations {
     @Test
     public void shouldStripLastModifiedFromOrigin304ResponseToStrongValidation() throws Exception {
         shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
-                "Last-Modified", DateUtils.formatDate(twoMinutesAgo));
+                "Last-Modified", DateUtils.formatStandardDate(twoMinutesAgo));
     }
 
     /*
@@ -421,7 +420,7 @@ public class TestProtocolRecommendations {
     private ClassicHttpRequest requestToPopulateStaleCacheEntry() throws Exception {
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control","public,max-age=5");
         resp1.setHeader("Etag","\"etag\"");
 
@@ -547,7 +546,7 @@ public class TestProtocolRecommendations {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("Cache-Control", "public, max-age=5");
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
 
@@ -588,7 +587,7 @@ public class TestProtocolRecommendations {
      */
     @Test
     public void testDoesNotAddNewWarningHeaderIfResponseArrivesStale() throws Exception {
-        originResponse.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         originResponse.setHeader("Cache-Control","public, max-age=5");
         originResponse.setHeader("ETag","\"etag\"");
 
@@ -601,7 +600,7 @@ public class TestProtocolRecommendations {
 
     @Test
     public void testForwardsExistingWarningHeadersOnResponseThatArrivesStale() throws Exception {
-        originResponse.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         originResponse.setHeader("Cache-Control","public, max-age=5");
         originResponse.setHeader("ETag","\"etag\"");
         originResponse.addHeader("Age","10");
@@ -727,13 +726,13 @@ public class TestProtocolRecommendations {
 
     @Test
     public void testDoesNotModifyDateOnRequests() throws Exception {
-        request.setHeader("Date", DateUtils.formatDate(new Date()));
+        request.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         testDoesNotModifyHeaderOnRequests("Date");
     }
 
     @Test
     public void testDoesNotModifyDateOnResponses() throws Exception {
-        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         testDoesNotModifyHeaderOnResponses("Date");
     }
 
@@ -745,7 +744,7 @@ public class TestProtocolRecommendations {
 
     @Test
     public void testDoesNotModifyExpiresOnResponses() throws Exception {
-        originResponse.setHeader("Expires", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Expires", DateUtils.formatStandardDate(Instant.now()));
         testDoesNotModifyHeaderOnResponses("Expires");
     }
 
@@ -764,7 +763,7 @@ public class TestProtocolRecommendations {
 
     @Test
     public void testDoesNotModifyIfModifiedSinceOnRequests() throws Exception {
-        request.setHeader("If-Modified-Since", DateUtils.formatDate(new Date()));
+        request.setHeader("If-Modified-Since", DateUtils.formatStandardDate(Instant.now()));
         testDoesNotModifyHeaderOnRequests("If-Modified-Since");
     }
 
@@ -784,13 +783,13 @@ public class TestProtocolRecommendations {
     @Test
     public void testDoesNotModifyIfUnmodifiedSinceOnRequests() throws Exception {
         request = new BasicClassicHttpRequest("DELETE", "/");
-        request.setHeader("If-Unmodified-Since", DateUtils.formatDate(new Date()));
+        request.setHeader("If-Unmodified-Since", DateUtils.formatStandardDate(Instant.now()));
         testDoesNotModifyHeaderOnRequests("If-Unmodified-Since");
     }
 
     @Test
     public void testDoesNotModifyLastModifiedOnResponses() throws Exception {
-        originResponse.setHeader("Last-Modified", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now()));
         testDoesNotModifyHeaderOnResponses("Last-Modified");
     }
 
@@ -863,13 +862,13 @@ public class TestProtocolRecommendations {
      */
     @Test
     public void testUsesLastModifiedDateForCacheConditionalRequests() throws Exception {
-        final Date twentySecondsAgo = new Date(now.getTime() - 20 * 1000L);
-        final String lmDate = DateUtils.formatDate(twentySecondsAgo);
+        final Instant twentySecondsAgo = now.plusSeconds(20);
+        final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
 
         final ClassicHttpRequest req1 =
             new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Last-Modified", lmDate);
         resp1.setHeader("Cache-Control","max-age=5");
 
@@ -902,13 +901,13 @@ public class TestProtocolRecommendations {
      */
     @Test
     public void testUsesBothLastModifiedAndETagForConditionalRequestsIfAvailable() throws Exception {
-        final Date twentySecondsAgo = new Date(now.getTime() - 20 * 1000L);
-        final String lmDate = DateUtils.formatDate(twentySecondsAgo);
+        final Instant twentySecondsAgo = now.plusSeconds(20);
+        final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
         final String etag = "\"etag\"";
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Last-Modified", lmDate);
         resp1.setHeader("Cache-Control","max-age=5");
         resp1.setHeader("ETag", etag);
@@ -944,14 +943,14 @@ public class TestProtocolRecommendations {
      */
     @Test
     public void testRevalidatesCachedResponseWithExpirationInThePast() throws Exception {
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date oneSecondFromNow = new Date(now.getTime() + 1 * 1000L);
-        final Date twoSecondsFromNow = new Date(now.getTime() + 2 * 1000L);
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant oneSecondFromNow = now.plusSeconds(1);
+        final Instant twoSecondsFromNow = now.plusSeconds(2);
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Expires",DateUtils.formatDate(oneSecondAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
+        resp1.setHeader("Expires",DateUtils.formatStandardDate(oneSecondAgo));
         resp1.setHeader("Cache-Control", "public");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -961,8 +960,8 @@ public class TestProtocolRecommendations {
         revalidate.setHeader("If-None-Match","\"etag\"");
 
         final ClassicHttpResponse resp2 = HttpTestUtils.make304Response();
-        resp2.setHeader("Date", DateUtils.formatDate(twoSecondsFromNow));
-        resp2.setHeader("Expires", DateUtils.formatDate(oneSecondFromNow));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(twoSecondsFromNow));
+        resp2.setHeader("Expires", DateUtils.formatStandardDate(oneSecondFromNow));
         resp2.setHeader("ETag","\"etag\"");
 
         Mockito.when(mockExecChain.proceed(RequestEquivalent.eq(revalidate), Mockito.any())).thenReturn(resp2);
@@ -988,17 +987,17 @@ public class TestProtocolRecommendations {
      */
     @Test
     public void testRetriesValidationThatResultsInAnOlderDated304Response() throws Exception {
-        final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
+        final Instant elevenSecondsAgo = now.minusSeconds(11);
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control","max-age=5");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp2 = HttpTestUtils.make304Response();
         resp2.setHeader("ETag","\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(elevenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(elevenSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -1110,7 +1109,7 @@ public class TestProtocolRecommendations {
         req1.setHeader("User-Agent", "agent1");
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Vary", "User-Agent");
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("ETag", "\"etag1\"");
@@ -1119,7 +1118,7 @@ public class TestProtocolRecommendations {
         req2.setHeader("User-Agent", "agent2");
 
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
-        resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp2.setHeader("Vary", "User-Agent");
         resp2.setHeader("Cache-Control", "max-age=3600");
         resp2.setHeader("ETag", "\"etag2\"");
@@ -1128,7 +1127,7 @@ public class TestProtocolRecommendations {
         req3.setHeader("User-Agent", "agent3");
 
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
         resp3.setHeader("ETag", "\"etag1\"");
 
         final ClassicHttpRequest req4 = new BasicClassicHttpRequest("GET", "/");
@@ -1149,8 +1148,8 @@ public class TestProtocolRecommendations {
 
         assertEquals(HttpStatus.SC_OK, result1.getCode());
         assertEquals("\"etag1\"", result1.getFirstHeader("ETag").getValue());
-        assertEquals(DateUtils.formatDate(now), result1.getFirstHeader("Date").getValue());
-        assertEquals(DateUtils.formatDate(now), result2.getFirstHeader("Date").getValue());
+        assertEquals(DateUtils.formatStandardDate(now), result1.getFirstHeader("Date").getValue());
+        assertEquals(DateUtils.formatStandardDate(now), result2.getFirstHeader("Date").getValue());
     }
 
     @Test
@@ -1160,7 +1159,7 @@ public class TestProtocolRecommendations {
         req1.setHeader("User-Agent", "agent1");
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Vary", "User-Agent");
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("ETag", "\"etag1\"");
@@ -1171,7 +1170,7 @@ public class TestProtocolRecommendations {
         req2.setHeader("User-Agent", "agent2");
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("ETag", "\"etag1\"");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
@@ -1210,7 +1209,7 @@ public class TestProtocolRecommendations {
         resp2.setHeader("Vary","User-Agent");
         resp2.setHeader("ETag", "\"etag2\"");
         resp2.setHeader("Cache-Control","max-age=3600");
-        resp2.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
 
         final ClassicHttpRequest req3 = HttpTestUtils.makeDefaultRequest();
         req3.setHeader("User-Agent", "agent3");
@@ -1258,14 +1257,14 @@ public class TestProtocolRecommendations {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("Cache-Control","max-age=3600");
         resp1.setHeader("ETag", "\"old-etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
         final ClassicHttpRequest req2 = new HttpPost("http://foo.example.com/bar");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("ETag", "\"new-etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Content-Location", "http://foo.example.com/");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
@@ -1294,7 +1293,7 @@ public class TestProtocolRecommendations {
         resp2.setVersion(HttpVersion.HTTP_1_0);
         resp2.setEntity(HttpTestUtils.makeBody(200));
         resp2.setHeader("Content-Length","200");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -1308,7 +1307,7 @@ public class TestProtocolRecommendations {
         resp2.setVersion(HttpVersion.HTTP_1_0);
         resp2.setEntity(HttpTestUtils.makeBody(200));
         resp2.setHeader("Content-Length","200");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Via","1.0 someproxy");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
@@ -1414,7 +1413,7 @@ public class TestProtocolRecommendations {
     public void cacheShouldUpdateWithNewCacheableResponse() throws Exception {
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("ETag", "\"etag1\"");
 
@@ -1423,7 +1422,7 @@ public class TestProtocolRecommendations {
         final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
         req2.setHeader("Cache-Control", "max-age=0");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Cache-Control", "max-age=3600");
         resp2.setHeader("ETag", "\"etag2\"");
 
@@ -1453,8 +1452,8 @@ public class TestProtocolRecommendations {
     public void expiresEqualToDateWithNoCacheControlIsNotCacheable() throws Exception {
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Expires", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
+        resp1.setHeader("Expires", DateUtils.formatStandardDate(now));
         resp1.removeHeaders("Cache-Control");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1476,8 +1475,8 @@ public class TestProtocolRecommendations {
     public void expiresPriorToDateWithNoCacheControlIsNotCacheable() throws Exception {
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
-        resp1.setHeader("Expires", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
+        resp1.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.removeHeaders("Cache-Control");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1571,7 +1570,7 @@ public class TestProtocolRecommendations {
     public void returns504ForStaleEntryWithOnlyIfCached() throws Exception {
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control","max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1590,7 +1589,7 @@ public class TestProtocolRecommendations {
 
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control","max-age=5");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1608,7 +1607,7 @@ public class TestProtocolRecommendations {
     public void issues304EvenWithWeakETag() throws Exception {
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "max-age=300");
         resp1.setHeader("ETag","W/\"weak-sauce\"");
 
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
index 18f5314..67f92f6 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
@@ -29,8 +29,9 @@ package org.apache.hc.client5.http.impl.cache;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.SocketTimeoutException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
 import java.util.Arrays;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
@@ -225,7 +226,7 @@ public class TestProtocolRequirements {
     public void testLowerOriginResponsesUpgradedToOurVersion1_1() throws Exception {
         originResponse = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         originResponse.setVersion(new ProtocolVersion("HTTP", 1, 2));
-        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         originResponse.setHeader("Server", "MockOrigin/1.0");
         originResponse.setEntity(body);
 
@@ -488,7 +489,7 @@ public class TestProtocolRequirements {
     private void testUnknownResponseStatusCodeIsNotCached(final int code) throws Exception {
 
         originResponse = new BasicClassicHttpResponse(code, "Moo");
-        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         originResponse.setHeader("Server", "MockOrigin/1.0");
         originResponse.setHeader("Cache-Control", "max-age=3600");
         originResponse.setEntity(body);
@@ -837,11 +838,10 @@ public class TestProtocolRequirements {
 
     @Test
     public void testHEADResponseWithUpdatedLastModifiedFieldMakeACacheEntryStale() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        testHEADResponseWithUpdatedEntityFieldsMakeACacheEntryStale("Last-Modified", DateUtils
-                .formatDate(tenSecondsAgo), DateUtils.formatDate(sixSecondsAgo));
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant sixSecondsAgo = now.minusSeconds(6);
+        testHEADResponseWithUpdatedEntityFieldsMakeACacheEntryStale("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo), DateUtils.formatStandardDate(sixSecondsAgo));
     }
 
     /*
@@ -1028,7 +1028,7 @@ public class TestProtocolRequirements {
     public void test206ResponseReturnedToClientMustHaveDateHeader() throws Exception {
         request.addHeader("Range", "bytes=0-50");
         originResponse = new BasicClassicHttpResponse(HttpStatus.SC_PARTIAL_CONTENT, "Partial Content");
-        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         originResponse.setHeader("Server", "MockOrigin/1.0");
         originResponse.setEntity(HttpTestUtils.makeBody(500));
         originResponse.setHeader("Content-Range", "bytes 0-499/1234");
@@ -1090,22 +1090,22 @@ public class TestProtocolRequirements {
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.addHeader("Accept-Encoding", "gzip");
 
-        final Date now = new Date();
-        final Date inOneHour = new Date(now.getTime() + 3600 * 1000L);
+        final Instant now = Instant.now();
+        final Instant inOneHour = Instant.now().plus(1, ChronoUnit.HOURS);
         originResponse.addHeader("Cache-Control", "max-age=3600");
-        originResponse.addHeader("Expires", DateUtils.formatDate(inOneHour));
+        originResponse.addHeader("Expires", DateUtils.formatStandardDate(inOneHour));
         originResponse.addHeader("Vary", "Accept-Encoding");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         req2.addHeader("Cache-Control", "no-cache");
         req2.addHeader("Accept-Encoding", "gzip");
-        final Date nextSecond = new Date(now.getTime() + 1000L);
-        final Date inTwoHoursPlusASec = new Date(now.getTime() + 2 * 3600 * 1000L + 1000L);
+        final Instant nextSecond = Instant.now().plusSeconds(1);
+        final Instant inTwoHoursPlusASec = now.plus(2, ChronoUnit.HOURS).plus(1, ChronoUnit.SECONDS);
 
         final ClassicHttpResponse originResponse2 = HttpTestUtils.make200Response();
-        originResponse2.setHeader("Date", DateUtils.formatDate(nextSecond));
+        originResponse2.setHeader("Date", DateUtils.formatStandardDate(nextSecond));
         originResponse2.setHeader("Cache-Control", "max-age=7200");
-        originResponse2.setHeader("Expires", DateUtils.formatDate(inTwoHoursPlusASec));
+        originResponse2.setHeader("Expires", DateUtils.formatStandardDate(inTwoHoursPlusASec));
         originResponse2.setHeader("Vary", "Accept-Encoding");
 
         final ClassicHttpRequest req3 = new BasicClassicHttpRequest("GET", "/");
@@ -1143,8 +1143,8 @@ public class TestProtocolRequirements {
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
 
-        final Date now = new Date();
-        final Date oneHourAgo = new Date(now.getTime() - 3600 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
         originResponse = HttpTestUtils.make200Response();
         originResponse.addHeader("Allow", "GET,HEAD");
         originResponse.addHeader("Cache-Control", "max-age=3600");
@@ -1153,7 +1153,7 @@ public class TestProtocolRequirements {
         originResponse.addHeader("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
         originResponse.addHeader("Content-Length", "128");
         originResponse.addHeader("Content-Type", "application/octet-stream");
-        originResponse.addHeader("Last-Modified", DateUtils.formatDate(oneHourAgo));
+        originResponse.addHeader("Last-Modified", DateUtils.formatStandardDate(oneHourAgo));
         originResponse.addHeader("ETag", "W/\"weak-tag\"");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
@@ -1187,8 +1187,8 @@ public class TestProtocolRequirements {
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
 
-        final Date now = new Date();
-        final Date oneHourAgo = new Date(now.getTime() - 3600 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
         originResponse.addHeader("Allow", "GET,HEAD");
         originResponse.addHeader("Cache-Control", "max-age=3600");
         originResponse.addHeader("Content-Language", "en");
@@ -1196,7 +1196,7 @@ public class TestProtocolRequirements {
         originResponse.addHeader("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
         originResponse.addHeader("Content-Length", "128");
         originResponse.addHeader("Content-Type", "application/octet-stream");
-        originResponse.addHeader("Last-Modified", DateUtils.formatDate(oneHourAgo));
+        originResponse.addHeader("Last-Modified", DateUtils.formatStandardDate(oneHourAgo));
         originResponse.addHeader("ETag", "\"strong-tag\"");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
@@ -1231,7 +1231,7 @@ public class TestProtocolRequirements {
     @Test
     public void test206ResponseIsNotCombinedWithPreviousContentIfETagDoesNotMatch() throws Exception {
 
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
@@ -1245,10 +1245,10 @@ public class TestProtocolRequirements {
         req2.setHeader("Cache-Control", "no-cache");
         req2.setHeader("Range", "bytes=0-50");
 
-        final Date inOneSecond = new Date(now.getTime() + 1000L);
+        final Instant inOneSecond = now.plusSeconds(1);
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_PARTIAL_CONTENT,
                 "Partial Content");
-        resp2.setHeader("Date", DateUtils.formatDate(inOneSecond));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(inOneSecond));
         resp2.setHeader("Server", resp1.getFirstHeader("Server").getValue());
         resp2.setHeader("ETag", "\"etag2\"");
         resp2.setHeader("Content-Range", "bytes 0-50/128");
@@ -1256,7 +1256,6 @@ public class TestProtocolRequirements {
         Arrays.fill(bytes2, (byte) 2);
         resp2.setEntity(new ByteArrayEntity(bytes2, null));
 
-        final Date inTwoSeconds = new Date(now.getTime() + 2000L);
         final ClassicHttpRequest req3 = new BasicClassicHttpRequest("GET", "/");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1289,13 +1288,13 @@ public class TestProtocolRequirements {
     @Test
     public void test206ResponseIsNotCombinedWithPreviousContentIfLastModifiedDoesNotMatch() throws Exception {
 
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        final Date oneHourAgo = new Date(now.getTime() - 3600L);
+        final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
         resp1.setHeader("Cache-Control", "max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(oneHourAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(oneHourAgo));
         final byte[] bytes1 = new byte[128];
         Arrays.fill(bytes1, (byte) 1);
         resp1.setEntity(new ByteArrayEntity(bytes1, null));
@@ -1304,18 +1303,17 @@ public class TestProtocolRequirements {
         req2.setHeader("Cache-Control", "no-cache");
         req2.setHeader("Range", "bytes=0-50");
 
-        final Date inOneSecond = new Date(now.getTime() + 1000L);
+        final Instant inOneSecond = now.plusSeconds(1);
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_PARTIAL_CONTENT,
                 "Partial Content");
-        resp2.setHeader("Date", DateUtils.formatDate(inOneSecond));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(inOneSecond));
         resp2.setHeader("Server", resp1.getFirstHeader("Server").getValue());
-        resp2.setHeader("Last-Modified", DateUtils.formatDate(now));
+        resp2.setHeader("Last-Modified", DateUtils.formatStandardDate(now));
         resp2.setHeader("Content-Range", "bytes 0-50/128");
         final byte[] bytes2 = new byte[51];
         Arrays.fill(bytes2, (byte) 2);
         resp2.setEntity(new ByteArrayEntity(bytes2, null));
 
-        final Date inTwoSeconds = new Date(now.getTime() + 2000L);
         final ClassicHttpRequest req3 = new BasicClassicHttpRequest("GET", "/");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -1384,7 +1382,7 @@ public class TestProtocolRequirements {
         request = new BasicClassicHttpRequest("GET", "/");
 
         originResponse = new BasicClassicHttpResponse(HttpStatus.SC_SEE_OTHER, "See Other");
-        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         originResponse.setHeader("Server", "MockServer/1.0");
         originResponse.setHeader("Cache-Control", "max-age=3600");
         originResponse.setHeader("Content-Type", "application/x-cachingclient-test");
@@ -1411,7 +1409,7 @@ public class TestProtocolRequirements {
         request.setHeader("If-None-Match", "\"etag\"");
 
         originResponse = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED,"Not Modified");
-        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         originResponse.setHeader("Server", "MockServer/1.0");
         originResponse.setHeader("ETag", "\"etag\"");
 
@@ -1501,8 +1499,8 @@ public class TestProtocolRequirements {
     @Test
     public void test304ResponseGeneratedFromCacheIncludesExpiresCacheControlAndOrVaryIfResponseMightDiffer() throws Exception {
 
-        final Date now = new Date();
-        final Date inTwoHours = new Date(now.getTime() + 2 * 3600 * 1000L);
+        final Instant now = Instant.now();
+        final Instant inTwoHours = now.plus(2, ChronoUnit.HOURS);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Accept-Encoding", "gzip");
@@ -1510,7 +1508,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("ETag", "\"v1\"");
         resp1.setHeader("Cache-Control", "max-age=7200");
-        resp1.setHeader("Expires", DateUtils.formatDate(inTwoHours));
+        resp1.setHeader("Expires", DateUtils.formatStandardDate(inTwoHours));
         resp1.setHeader("Vary", "Accept-Encoding");
         resp1.setEntity(HttpTestUtils.makeBody(ENTITY_LENGTH));
 
@@ -1521,7 +1519,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("ETag", "\"v2\"");
         resp2.setHeader("Cache-Control", "max-age=3600");
-        resp2.setHeader("Expires", DateUtils.formatDate(inTwoHours));
+        resp2.setHeader("Expires", DateUtils.formatStandardDate(inTwoHours));
         resp2.setHeader("Vary", "Accept-Encoding");
         resp2.setEntity(HttpTestUtils.makeBody(ENTITY_LENGTH));
 
@@ -1556,8 +1554,8 @@ public class TestProtocolRequirements {
     @Test
     public void test304GeneratedFromCacheOnWeakValidatorDoesNotIncludeOtherEntityHeaders() throws Exception {
 
-        final Date now = new Date();
-        final Date oneHourAgo = new Date(now.getTime() - 3600 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
 
@@ -1569,7 +1567,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Content-Length", "128");
         resp1.setHeader("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
         resp1.setHeader("Content-Type", "application/octet-stream");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(oneHourAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(oneHourAgo));
         resp1.setHeader("Cache-Control", "max-age=7200");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
@@ -1601,7 +1599,7 @@ public class TestProtocolRequirements {
     @Test
     public void testNotModifiedOfNonCachedEntityShouldRevalidateWithUnconditionalGET() throws Exception {
 
-        final Date now = new Date();
+        final Instant now = Instant.now();
 
         // load cache with cacheable entry
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
@@ -1642,8 +1640,8 @@ public class TestProtocolRequirements {
     @Test
     public void testCacheEntryIsUpdatedWithNewFieldValuesIn304Response() throws Exception {
 
-        final Date now = new Date();
-        final Date inFiveSeconds = new Date(now.getTime() + 5000L);
+        final Instant now = Instant.now();
+        final Instant inFiveSeconds = now.plusSeconds(5);
 
         final ClassicHttpRequest initialRequest = new BasicClassicHttpRequest("GET", "/");
 
@@ -1659,14 +1657,14 @@ public class TestProtocolRequirements {
 
         // to be used if the cache generates a conditional validation
         final ClassicHttpResponse conditionalResponse = HttpTestUtils.make304Response();
-        conditionalResponse.setHeader("Date", DateUtils.formatDate(inFiveSeconds));
+        conditionalResponse.setHeader("Date", DateUtils.formatStandardDate(inFiveSeconds));
         conditionalResponse.setHeader("Server", "MockUtils/1.0");
         conditionalResponse.setHeader("ETag", "\"etag\"");
         conditionalResponse.setHeader("X-Extra", "junk");
 
         // to be used if the cache generates an unconditional validation
         final ClassicHttpResponse unconditionalResponse = HttpTestUtils.make200Response();
-        unconditionalResponse.setHeader("Date", DateUtils.formatDate(inFiveSeconds));
+        unconditionalResponse.setHeader("Date", DateUtils.formatStandardDate(inFiveSeconds));
         unconditionalResponse.setHeader("ETag", "\"etag\"");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(cachedResponse);
@@ -1677,7 +1675,7 @@ public class TestProtocolRequirements {
 
         Mockito.verify(mockExecChain, Mockito.times(2)).proceed(Mockito.any(), Mockito.any());
 
-        Assert.assertEquals(DateUtils.formatDate(inFiveSeconds), result.getFirstHeader("Date").getValue());
+        Assert.assertEquals(DateUtils.formatStandardDate(inFiveSeconds), result.getFirstHeader("Date").getValue());
         Assert.assertEquals("junk", result.getFirstHeader("X-Extra").getValue());
     }
 
@@ -1821,13 +1819,13 @@ public class TestProtocolRequirements {
     @Test
     public void testMustReturnACacheEntryIfItCanRevalidateIt() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
-        final Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant nineSecondsAgo = now.minusSeconds(9);
+        final Instant eightSecondsAgo = now.minusSeconds(8);
 
         final Header[] hdrs = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(nineSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(nineSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=0"),
                 new BasicHeader("ETag", "\"etag\""),
                 new BasicHeader("Content-Length", "128")
@@ -1846,7 +1844,7 @@ public class TestProtocolRequirements {
         validate.setHeader("If-None-Match", "\"etag\"");
 
         final ClassicHttpResponse notModified = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        notModified.setHeader("Date", DateUtils.formatDate(now));
+        notModified.setHeader("Date", DateUtils.formatStandardDate(now));
         notModified.setHeader("ETag", "\"etag\"");
 
         Mockito.when(mockCache.getCacheEntry(Mockito.eq(host), RequestEquivalent.eq(request))).thenReturn(entry);
@@ -1874,13 +1872,13 @@ public class TestProtocolRequirements {
     @Test
     public void testMustReturnAFreshEnoughCacheEntryIfItHasIt() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
-        final Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant nineSecondsAgo = now.plusSeconds(9);
+        final Instant eightSecondsAgo = now.plusSeconds(8);
 
         final Header[] hdrs = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(nineSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(nineSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length", "128")
         };
@@ -1917,16 +1915,16 @@ public class TestProtocolRequirements {
     @Test
     public void testMustServeAppropriateErrorOrWarningIfNoOriginCommunicationPossible() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
-        final Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant nineSecondsAgo = now.plusSeconds(9);
+        final Instant eightSecondsAgo = now.plusSeconds(8);
 
         final Header[] hdrs = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(nineSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(nineSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=0"),
                 new BasicHeader("Content-Length", "128"),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo))
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo))
         };
 
         final byte[] bytes = new byte[128];
@@ -1975,11 +1973,11 @@ public class TestProtocolRequirements {
     @Test
     public void test1xxWarningsAreDeletedAfterSuccessfulRevalidation() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 25 * 1000L);
+        final Instant now = Instant.now();
+        final Instant twentyFiveSecondsAgo = now.minusSeconds(25);
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twentyFiveSecondsAgo));
         resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Cache-Control", "max-age=5");
         resp1.setHeader("Warning", "110 squid \"stale stuff\"");
@@ -1992,7 +1990,7 @@ public class TestProtocolRequirements {
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED,
                 "Not Modified");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Server", "MockServer/1.0");
         resp2.setHeader("ETag", "\"etag\"");
         resp2.setHeader("Via", "1.1 fred");
@@ -2036,11 +2034,11 @@ public class TestProtocolRequirements {
      */
     @Test
     public void test2xxWarningsAreNotDeletedAfterSuccessfulRevalidation() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Cache-Control", "max-age=5");
         resp1.setHeader("Via", "1.1 xproxy");
@@ -2053,7 +2051,7 @@ public class TestProtocolRequirements {
 
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED,
                 "Not Modified");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
         resp2.setHeader("Server", "MockServer/1.0");
         resp2.setHeader("ETag", "\"etag\"");
         resp1.setHeader("Via", "1.1 xproxy");
@@ -2102,13 +2100,13 @@ public class TestProtocolRequirements {
     @Test
     public void testAgeHeaderPopulatedFromCacheEntryCurrentAge() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
-        final Date eightSecondsAgo = new Date(now.getTime() - 8 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant nineSecondsAgo = now.minusSeconds(9);
+        final Instant eightSecondsAgo = now.minusSeconds(8);
 
         final Header[] hdrs = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(nineSecondsAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(nineSecondsAgo)),
                 new BasicHeader("Cache-Control", "max-age=3600"),
                 new BasicHeader("Content-Length", "128")
         };
@@ -2148,16 +2146,16 @@ public class TestProtocolRequirements {
     @Test
     public void testHeuristicCacheOlderThan24HoursHasWarningAttached() throws Exception {
 
-        final Date now = new Date();
-        final Date thirtySixHoursAgo = new Date(now.getTime() - 36 * 3600 * 1000L);
-        final Date oneYearAgo = new Date(now.getTime() - 365 * 24 * 3600 * 1000L);
-        final Date requestTime = new Date(thirtySixHoursAgo.getTime() - 1000L);
-        final Date responseTime = new Date(thirtySixHoursAgo.getTime() + 1000L);
+        final Instant now = Instant.now();
+        final Instant thirtySixHoursAgo = now.minus(26, ChronoUnit.HOURS);
+        final Instant oneYearAgo = now.minus(1, ChronoUnit.HOURS);
+        final Instant requestTime = thirtySixHoursAgo.minusSeconds(1);
+        final Instant responseTime = thirtySixHoursAgo.plusSeconds(1);
 
         final Header[] hdrs = new Header[] {
-                new BasicHeader("Date", DateUtils.formatDate(thirtySixHoursAgo)),
+                new BasicHeader("Date", DateUtils.formatStandardDate(thirtySixHoursAgo)),
                 new BasicHeader("Cache-Control", "public"),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(oneYearAgo)),
+                new BasicHeader("Last-Modified", DateUtils.formatStandardDate(oneYearAgo)),
                 new BasicHeader("Content-Length", "128")
         };
 
@@ -2172,7 +2170,7 @@ public class TestProtocolRequirements {
 
         final ClassicHttpResponse validated = HttpTestUtils.make200Response();
         validated.setHeader("Cache-Control", "public");
-        validated.setHeader("Last-Modified", DateUtils.formatDate(oneYearAgo));
+        validated.setHeader("Last-Modified", DateUtils.formatStandardDate(oneYearAgo));
         validated.setHeader("Content-Length", "128");
         validated.setEntity(new ByteArrayEntity(bytes, null));
 
@@ -2228,14 +2226,14 @@ public class TestProtocolRequirements {
     @Test
     public void testKeepsMostRecentDateHeaderForFreshResponse() throws Exception {
 
-        final Date now = new Date();
-        final Date inFiveSecond = new Date(now.getTime() + 5 * 1000L);
+        final Instant now = Instant.now();
+        final Instant inFiveSecond = now.plusSeconds(5);
 
         // put an entry in the cache
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
 
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(inFiveSecond));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(inFiveSecond));
         resp1.setHeader("ETag", "\"etag1\"");
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("Content-Length", "128");
@@ -2245,7 +2243,7 @@ public class TestProtocolRequirements {
         req2.setHeader("Cache-Control", "no-cache");
 
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
-        resp2.setHeader("Date", DateUtils.formatDate(now)); // older
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now)); // older
         resp2.setHeader("ETag", "\"etag2\"");
         resp2.setHeader("Cache-Control", "max-age=3600");
         resp2.setHeader("Content-Length", "128");
@@ -2353,10 +2351,10 @@ public class TestProtocolRequirements {
      */
     @Test
     public void testSubrangeGETMustUseStrongComparisonForCachedResponse() throws Exception {
-        final Date now = new Date();
+        final Instant now = Instant.now();
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=3600");
         resp1.setHeader("ETag", "\"etag\"");
 
@@ -2389,14 +2387,14 @@ public class TestProtocolRequirements {
     @Test
     public void testValidationMustUseETagIfProvidedByOriginServer() throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("ETag", "W/\"etag\"");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
@@ -2455,20 +2453,20 @@ public class TestProtocolRequirements {
      */
     @Test
     public void testConditionalRequestWhereNotAllValidatorsMatchCannotBeServedFromCache() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        final Date twentySecondsAgo = new Date(now.getTime() - 20 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        final Instant twentySecondsAgo = now.plusSeconds(20);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("ETag", "W/\"etag\"");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         req2.setHeader("If-None-Match", "W/\"etag\"");
-        req2.setHeader("If-Modified-Since", DateUtils.formatDate(twentySecondsAgo));
+        req2.setHeader("If-Modified-Since", DateUtils.formatStandardDate(twentySecondsAgo));
 
         // must hit the origin again for the second request
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -2482,19 +2480,19 @@ public class TestProtocolRequirements {
 
     @Test
     public void testConditionalRequestWhereAllValidatorsMatchMayBeServedFromCache() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(now));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(now));
         resp1.setHeader("Cache-Control", "max-age=3600");
-        resp1.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("ETag", "W/\"etag\"");
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         req2.setHeader("If-None-Match", "W/\"etag\"");
-        req2.setHeader("If-Modified-Since", DateUtils.formatDate(tenSecondsAgo));
+        req2.setHeader("If-Modified-Since", DateUtils.formatStandardDate(tenSecondsAgo));
 
         // may hit the origin again for the second request
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -2594,7 +2592,7 @@ public class TestProtocolRequirements {
 
     @Test
     public void testDoesNotModifyLastModifiedHeaderFromOrigin() throws Exception {
-        final String lm = DateUtils.formatDate(new Date());
+        final String lm = DateUtils.formatStandardDate(Instant.now());
         testDoesNotModifyHeaderFromOrigin("Last-Modified", lm);
     }
 
@@ -2663,8 +2661,8 @@ public class TestProtocolRequirements {
 
     @Test
     public void testDoesNotModifyLastModifiedFromOriginOnCacheHit() throws Exception {
-        final String lm = DateUtils.formatDate(new Date(System.currentTimeMillis() - 10 * 1000L));
-        testDoesNotModifyHeaderFromOriginOnCacheHit("Last-Modified", lm);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
+        testDoesNotModifyHeaderFromOriginOnCacheHit("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
     }
 
     private void testDoesNotAddHeaderOnCacheHit(final String header) throws Exception {
@@ -2736,9 +2734,8 @@ public class TestProtocolRequirements {
 
     @Test
     public void testDoesNotModifyLastModifiedHeaderOnRequest() throws Exception {
-        final long tenSecondsAgo = System.currentTimeMillis() - 10 * 1000L;
-        final String lm = DateUtils.formatDate(new Date(tenSecondsAgo));
-        testDoesNotModifyHeaderOnRequest("Last-Modified", lm);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
+        testDoesNotModifyHeaderOnRequest("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
     }
 
     private void testDoesNotAddHeaderToRequestIfNotPresent(final String header) throws Exception {
@@ -2786,16 +2783,14 @@ public class TestProtocolRequirements {
      */
     @Test
     public void testDoesNotModifyExpiresHeaderFromOrigin() throws Exception {
-        final long inTenSeconds = System.currentTimeMillis() + 10 * 1000L;
-        final String expires = DateUtils.formatDate(new Date(inTenSeconds));
-        testDoesNotModifyHeaderFromOrigin("Expires", expires);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
+        testDoesNotModifyHeaderFromOrigin("Expires", DateUtils.formatStandardDate(tenSecondsAgo));
     }
 
     @Test
     public void testDoesNotModifyExpiresHeaderFromOriginOnCacheHit() throws Exception {
-        final long inTenSeconds = System.currentTimeMillis() + 10 * 1000L;
-        final String expires = DateUtils.formatDate(new Date(inTenSeconds));
-        testDoesNotModifyHeaderFromOriginOnCacheHit("Expires", expires);
+        final Instant inTenSeconds = Instant.now().plusSeconds(10);
+        testDoesNotModifyHeaderFromOriginOnCacheHit("Expires", DateUtils.formatStandardDate(inTenSeconds));
     }
 
     @Test
@@ -3047,8 +3042,8 @@ public class TestProtocolRequirements {
         r.setHeader("Content-Location","http://foo.example.com/other");
         r.setHeader("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
         r.setHeader("Content-Type", "text/html;charset=utf-8");
-        r.setHeader("Expires", DateUtils.formatDate(new Date(System.currentTimeMillis() + 10 * 1000L)));
-        r.setHeader("Last-Modified", DateUtils.formatDate(new Date(System.currentTimeMillis() - 10 * 1000L)));
+        r.setHeader("Expires", DateUtils.formatStandardDate(Instant.now().plusSeconds(10)));
+        r.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now().minusSeconds(10)));
         r.setHeader("Location", "http://foo.example.com/other2");
         r.setHeader("Pragma", "x-pragma");
         r.setHeader("Retry-After","180");
@@ -3065,7 +3060,7 @@ public class TestProtocolRequirements {
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         req2.setHeader("Cache-Control", "max-age=0, max-stale=0");
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp2.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp2.setHeader("Server", "MockServer/1.0");
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
@@ -3100,13 +3095,13 @@ public class TestProtocolRequirements {
         req2.setHeader("Cache-Control", "max-age=0, max-stale=0");
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
         resp2.setHeader("Cache-Control", "max-age=1800");
-        resp2.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp2.setHeader("Server", "MockServer/1.0");
         resp2.setHeader("Allow", "GET,HEAD");
         resp2.setHeader("Content-Language", "en,en-us");
         resp2.setHeader("Content-Location", "http://foo.example.com/new");
         resp2.setHeader("Content-Type","text/html");
-        resp2.setHeader("Expires", DateUtils.formatDate(new Date(System.currentTimeMillis() + 5 * 1000L)));
+        resp2.setHeader("Expires", DateUtils.formatStandardDate(Instant.now().plusSeconds(5)));
         resp2.setHeader("Location", "http://foo.example.com/new2");
         resp2.setHeader("Pragma","x-new-pragma");
         resp2.setHeader("Retry-After","120");
@@ -3194,14 +3189,14 @@ public class TestProtocolRequirements {
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_PARTIAL_CONTENT, "Partial Content");
         resp1.setEntity(HttpTestUtils.makeBody(50));
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
         resp1.setHeader("Cache-Control","max-age=3600");
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("ETag","\"etag1\"");
@@ -3216,7 +3211,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Cache-Control","max-age=3600");
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3225,7 +3220,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
 
@@ -3237,9 +3232,9 @@ public class TestProtocolRequirements {
     @Test
     public void testCannotCombinePartialResponseIfCacheEntryDoesNotHaveACacheValidator() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3249,7 +3244,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Cache-Control","max-age=3600");
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3262,7 +3257,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("ETag","\"etag1\"");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3271,7 +3266,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
 
@@ -3283,9 +3278,9 @@ public class TestProtocolRequirements {
     @Test
     public void testCannotCombinePartialResponseIfCacheValidatorsDoNotStronglyMatch() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3296,7 +3291,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("ETag","\"etag1\"");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3309,7 +3304,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("ETag","\"etag2\"");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3318,7 +3313,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
 
@@ -3330,9 +3325,9 @@ public class TestProtocolRequirements {
     @Test
     public void testMustDiscardLeastRecentPartialResponseIfIncomingRequestDoesNotHaveCacheValidator() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3343,7 +3338,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("ETag","\"etag1\"");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3355,7 +3350,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Cache-Control","max-age=3600");
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3365,7 +3360,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         // must make this request; cannot serve from cache
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
@@ -3378,9 +3373,9 @@ public class TestProtocolRequirements {
     @Test
     public void testMustDiscardLeastRecentPartialResponseIfCachedResponseDoesNotHaveCacheValidator() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3390,7 +3385,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Cache-Control","max-age=3600");
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3403,7 +3398,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("ETag","\"etag1\"");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3413,7 +3408,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         // must make this request; cannot serve from cache
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
@@ -3426,9 +3421,9 @@ public class TestProtocolRequirements {
     @Test
     public void testMustDiscardLeastRecentPartialResponseIfCacheValidatorsDoNotStronglyMatch() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3439,7 +3434,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("Etag","\"etag1\"");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3452,7 +3447,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("ETag","\"etag2\"");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3462,7 +3457,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         // must make this request; cannot serve from cache
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
@@ -3475,9 +3470,9 @@ public class TestProtocolRequirements {
     @Test
     public void testMustDiscardLeastRecentPartialResponseIfCacheValidatorsDoNotStronglyMatchEvenIfResponsesOutOfOrder() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
-        final Date twoSecondsAgo = new Date(now.getTime() - 2 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
+        final Instant twoSecondsAgo = Instant.now().plusSeconds(2);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3488,7 +3483,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("Etag","\"etag1\"");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3501,7 +3496,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("ETag","\"etag2\"");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(twoSecondsAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3511,7 +3506,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         // must make this request; cannot serve from cache
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
@@ -3524,8 +3519,8 @@ public class TestProtocolRequirements {
     @Test
     public void testMustDiscardCachedPartialResponseIfCacheValidatorsDoNotStronglyMatchAndDateHeadersAreEqual() throws Exception {
 
-        final Date now = new Date();
-        final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
+        final Instant now = Instant.now();
+        final Instant oneSecondAgo = now.minusSeconds(1);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         req1.setHeader("Range","bytes=0-49");
@@ -3536,7 +3531,7 @@ public class TestProtocolRequirements {
         resp1.setHeader("Content-Range","bytes 0-49/128");
         resp1.setHeader("Etag","\"etag1\"");
         resp1.setHeader("Server","MockServer/1.0");
-        resp1.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -3549,7 +3544,7 @@ public class TestProtocolRequirements {
         resp2.setHeader("Content-Range","bytes 50-127/128");
         resp2.setHeader("ETag","\"etag2\"");
         resp2.setHeader("Server","MockServer/1.0");
-        resp2.setHeader("Date", DateUtils.formatDate(oneSecondAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(oneSecondAgo));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp2);
 
@@ -3559,7 +3554,7 @@ public class TestProtocolRequirements {
         final ClassicHttpResponse resp3 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         resp3.setEntity(HttpTestUtils.makeBody(128));
         resp3.setHeader("Server","MockServer/1.0");
-        resp3.setHeader("Date", DateUtils.formatDate(now));
+        resp3.setHeader("Date", DateUtils.formatStandardDate(now));
 
         // must make this request; cannot serve from cache
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp3);
@@ -4147,10 +4142,10 @@ public class TestProtocolRequirements {
 
     @Test
     public void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponsesWithSMaxAge() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date",DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date",DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("ETag","\"etag\"");
         resp1.setHeader("Cache-Control","s-maxage=5");
 
@@ -4159,10 +4154,10 @@ public class TestProtocolRequirements {
 
     @Test
     public void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponsesWithMustRevalidate() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date",DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date",DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("ETag","\"etag\"");
         resp1.setHeader("Cache-Control","maxage=5, must-revalidate");
 
@@ -4184,11 +4179,11 @@ public class TestProtocolRequirements {
      */
     @Test
     public void testWarning110IsAddedToStaleResponses() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control","max-age=5");
         resp1.setHeader("Etag","\"etag\"");
 
@@ -4345,9 +4340,9 @@ public class TestProtocolRequirements {
     @Test
     public void testStaleEntryWithMustRevalidateIsNotUsedWithoutRevalidatingWithOrigin() throws Exception {
         final ClassicHttpResponse response = HttpTestUtils.make200Response();
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        response.setHeader("Date",DateUtils.formatDate(tenSecondsAgo));
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        response.setHeader("Date",DateUtils.formatStandardDate(tenSecondsAgo));
         response.setHeader("ETag","\"etag1\"");
         response.setHeader("Cache-Control","max-age=5, must-revalidate");
 
@@ -4380,10 +4375,10 @@ public class TestProtocolRequirements {
     @Test
     public void testGenerates504IfCannotRevalidateAMustRevalidateEntry() throws Exception {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control","max-age=5,must-revalidate");
 
         testGenerates504IfCannotRevalidateStaleResponse(resp1);
@@ -4399,9 +4394,9 @@ public class TestProtocolRequirements {
     public void testStaleEntryWithProxyRevalidateOnSharedCacheIsNotUsedWithoutRevalidatingWithOrigin() throws Exception {
         if (config.isSharedCache()) {
             final ClassicHttpResponse response = HttpTestUtils.make200Response();
-            final Date now = new Date();
-            final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-            response.setHeader("Date",DateUtils.formatDate(tenSecondsAgo));
+            final Instant now = Instant.now();
+            final Instant tenSecondsAgo = now.minusSeconds(10);
+            response.setHeader("Date",DateUtils.formatStandardDate(tenSecondsAgo));
             response.setHeader("ETag","\"etag1\"");
             response.setHeader("Cache-Control","max-age=5, proxy-revalidate");
 
@@ -4413,10 +4408,10 @@ public class TestProtocolRequirements {
     public void testGenerates504IfSharedCacheCannotRevalidateAProxyRevalidateEntry() throws Exception {
         if (config.isSharedCache()) {
             final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-            final Date now = new Date();
-            final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+            final Instant now = Instant.now();
+            final Instant tenSecondsAgo = now.minusSeconds(10);
             resp1.setHeader("ETag","\"etag\"");
-            resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+            resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
             resp1.setHeader("Cache-Control","max-age=5,proxy-revalidate");
 
             testGenerates504IfCannotRevalidateStaleResponse(resp1);
@@ -5044,18 +5039,18 @@ public class TestProtocolRequirements {
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
 
-        final Date now = new Date();
-        final Date twentySecondsAgo = new Date(now.getTime() - 20 * 1000L);
+        final Instant now = Instant.now();
+        final Instant twentySecondsAgo = now.plusSeconds(20);
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(twentySecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(twentySecondsAgo));
         resp1.setHeader("Cache-Control","public,max-age=5");
         resp1.setHeader("ETag", "\"etag1\"");
         final String oldWarning = "113 wilma \"stale\"";
         resp1.setHeader("Warning", oldWarning);
 
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not Modified");
-        resp2.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp2.setHeader("ETag", "\"etag1\"");
         final String newWarning = "113 betty \"stale too\"";
         resp2.setHeader("Warning", newWarning);
@@ -5090,7 +5085,7 @@ public class TestProtocolRequirements {
      */
     @Test
     public void testWarnDatesAreAddedToWarningsOnLowerProtocolVersions() throws Exception {
-        final String dateHdr = DateUtils.formatDate(new Date());
+        final String dateHdr = DateUtils.formatStandardDate(Instant.now());
         final String origWarning = "110 fred \"stale\"";
         originResponse.setCode(HttpStatus.SC_OK);
         originResponse.setVersion(HttpVersion.HTTP_1_0);
@@ -5130,11 +5125,11 @@ public class TestProtocolRequirements {
      */
     @Test
     public void testStripsBadlyDatedWarningsFromForwardedResponses() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        originResponse.setHeader("Date", DateUtils.formatDate(now));
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(now));
         originResponse.addHeader("Warning", "110 fred \"stale\", 110 wilma \"stale\" \""
-                + DateUtils.formatDate(tenSecondsAgo) + "\"");
+                + DateUtils.formatStandardDate(tenSecondsAgo) + "\"");
         originResponse.setHeader("Cache-Control","no-cache,no-store");
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
 
@@ -5147,11 +5142,11 @@ public class TestProtocolRequirements {
 
     @Test
     public void testStripsBadlyDatedWarningsFromStoredResponses() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        originResponse.setHeader("Date", DateUtils.formatDate(now));
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(now));
         originResponse.addHeader("Warning", "110 fred \"stale\", 110 wilma \"stale\" \""
-                + DateUtils.formatDate(tenSecondsAgo) + "\"");
+                + DateUtils.formatStandardDate(tenSecondsAgo) + "\"");
         originResponse.setHeader("Cache-Control","public,max-age=3600");
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
 
@@ -5164,11 +5159,11 @@ public class TestProtocolRequirements {
 
     @Test
     public void testRemovesWarningHeaderIfAllWarnValuesAreBadlyDated() throws Exception {
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        originResponse.setHeader("Date", DateUtils.formatDate(now));
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
+        originResponse.setHeader("Date", DateUtils.formatStandardDate(now));
         originResponse.addHeader("Warning", "110 wilma \"stale\" \""
-                + DateUtils.formatDate(tenSecondsAgo) + "\"");
+                + DateUtils.formatStandardDate(tenSecondsAgo) + "\"");
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
 
         final ClassicHttpResponse result = execute(request);
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
index c40fe4a..797f4d8 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
@@ -32,7 +32,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.util.Date;
+import java.time.Instant;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 
@@ -80,8 +80,6 @@ public class TestRFC5861Compliance {
     ExecChain mockExecChain;
     @Mock
     ExecRuntime mockExecRuntime;
-    @Mock
-    HttpCache mockCache;
     ClassicHttpRequest request;
     ClassicHttpResponse originResponse;
     CacheConfig config;
@@ -147,7 +145,7 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInResponseIsTrueReturnsStaleEntryWithWarning()
             throws Exception{
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=60");
@@ -169,7 +167,7 @@ public class TestRFC5861Compliance {
     @Test
     public void testConsumesErrorResponseWhenServingStale()
             throws Exception{
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=60");
@@ -196,7 +194,7 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInResponseYieldsToMustRevalidate()
             throws Exception{
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=60, must-revalidate");
@@ -219,7 +217,7 @@ public class TestRFC5861Compliance {
     public void testStaleIfErrorInResponseYieldsToProxyRevalidateForSharedCache()
             throws Exception{
         assertTrue(config.isSharedCache());
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=60, proxy-revalidate");
@@ -245,7 +243,7 @@ public class TestRFC5861Compliance {
                 .setSharedCache(false).build();
         impl = new CachingExec(new BasicHttpCache(configUnshared), null, configUnshared);
 
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=60, proxy-revalidate");
@@ -267,7 +265,7 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInResponseYieldsToExplicitFreshnessRequest()
             throws Exception{
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=60");
@@ -290,7 +288,7 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInRequestIsTrueReturnsStaleEntryWithWarning()
             throws Exception{
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5");
@@ -313,10 +311,10 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInRequestIsTrueReturnsStaleNonRevalidatableEntryWithWarning()
         throws Exception {
-        final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
         resp1.setHeader("Cache-Control", "public, max-age=5");
 
         final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
@@ -337,8 +335,8 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInResponseIsFalseReturnsError()
             throws Exception{
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5, stale-if-error=2");
@@ -361,8 +359,8 @@ public class TestRFC5861Compliance {
     @Test
     public void testStaleIfErrorInRequestIsFalseReturnsError()
             throws Exception{
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
                 "public, max-age=5");
@@ -403,11 +401,11 @@ public class TestRFC5861Compliance {
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
 
@@ -442,10 +440,10 @@ public class TestRFC5861Compliance {
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
 
@@ -484,11 +482,11 @@ public class TestRFC5861Compliance {
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
         resp1.setHeader("Cache-Control", "private, stale-while-revalidate=15");
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         req2.setHeader("If-None-Match","\"etag\"");
@@ -518,8 +516,8 @@ public class TestRFC5861Compliance {
     public void testStaleWhileRevalidateYieldsToMustRevalidate()
         throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         config = CacheConfig.custom()
                 .setMaxCacheEntries(MAX_ENTRIES)
@@ -532,13 +530,13 @@ public class TestRFC5861Compliance {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, must-revalidate");
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, must-revalidate");
         resp2.setHeader("ETag","\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -565,8 +563,8 @@ public class TestRFC5861Compliance {
     public void testStaleWhileRevalidateYieldsToProxyRevalidateForSharedCache()
         throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         config = CacheConfig.custom()
                 .setMaxCacheEntries(MAX_ENTRIES)
@@ -580,13 +578,13 @@ public class TestRFC5861Compliance {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, proxy-revalidate");
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, proxy-revalidate");
         resp2.setHeader("ETag","\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
@@ -613,8 +611,8 @@ public class TestRFC5861Compliance {
     public void testStaleWhileRevalidateYieldsToExplicitFreshnessRequest()
         throws Exception {
 
-        final Date now = new Date();
-        final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
+        final Instant now = Instant.now();
+        final Instant tenSecondsAgo = now.minusSeconds(10);
 
         config = CacheConfig.custom()
                 .setMaxCacheEntries(MAX_ENTRIES)
@@ -628,14 +626,14 @@ public class TestRFC5861Compliance {
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
         resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
         resp1.setHeader("ETag","\"etag\"");
-        resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
+        resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
 
         final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
         req2.setHeader("Cache-Control","min-fresh=2");
         final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
         resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
         resp2.setHeader("ETag","\"etag\"");
-        resp2.setHeader("Date", DateUtils.formatDate(now));
+        resp2.setHeader("Date", DateUtils.formatStandardDate(now));
 
         Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(resp1);
 
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java
index b374d28..14681a2 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java
@@ -26,7 +26,7 @@
  */
 package org.apache.hc.client5.http.impl.cache;
 
-import java.util.Date;
+import java.time.Instant;
 import java.util.Random;
 
 import org.apache.hc.client5.http.auth.StandardAuthScheme;
@@ -52,24 +52,20 @@ public class TestResponseCachingPolicy {
     private final int[] acceptableCodes = new int[] { HttpStatus.SC_OK,
             HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION, HttpStatus.SC_MULTIPLE_CHOICES,
             HttpStatus.SC_MOVED_PERMANENTLY, HttpStatus.SC_GONE };
-    private Date now;
-    private Date tenSecondsFromNow;
-    private Date sixSecondsAgo;
-
-    static String formatDate(final Date date) {
-        return DateUtils.formatStandardDate(DateUtils.toInstant(date));
-    }
+    private Instant now;
+    private Instant tenSecondsFromNow;
+    private Instant sixSecondsAgo;
 
     @Before
     public void setUp() throws Exception {
-        now = new Date();
-        sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
-        tenSecondsFromNow = new Date(now.getTime() + 10 * 1000L);
+        now = Instant.now();
+        sixSecondsAgo = now.minusSeconds(6);
+        tenSecondsFromNow = now.plusSeconds(10);
 
         policy = new ResponseCachingPolicy(0, true, false, false);
         request = new BasicHttpRequest("GET","/");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "");
-        response.setHeader("Date", formatDate(new Date()));
+        response.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         response.setHeader("Content-Length", "0");
     }
 
@@ -209,7 +205,7 @@ public class TestResponseCachingPolicy {
     public void testNon206WithExplicitExpiresIsCacheable() {
         final int status = getRandomStatus();
         response.setCode(status);
-        response.setHeader("Expires", formatDate(new Date()));
+        response.setHeader("Expires", DateUtils.formatStandardDate(Instant.now()));
         Assert.assertTrue(policy.isResponseCacheable("GET", response));
     }
 
@@ -364,7 +360,7 @@ public class TestResponseCachingPolicy {
         Assert.assertTrue(policy.isResponseCacheable("GET", response));
 
         response = new BasicHttpResponse(HttpStatus.SC_OK, "");
-        response.setHeader("Date", formatDate(new Date()));
+        response.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         response.addHeader("Cache-Control", "no-transform");
         response.setHeader("Content-Length", "0");
 
@@ -379,7 +375,7 @@ public class TestResponseCachingPolicy {
         Assert.assertTrue(policy.isResponseCacheable("HEAD", response));
 
         response = new BasicHttpResponse(HttpStatus.SC_OK, "");
-        response.setHeader("Date", formatDate(new Date()));
+        response.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         response.addHeader("Cache-Control", "no-transform");
         response.setHeader("Content-Length", "0");
 
@@ -484,8 +480,8 @@ public class TestResponseCachingPolicy {
 
     @Test
     public void testResponsesWithMultipleDateHeadersAreNotCacheable() {
-        response.addHeader("Date", formatDate(now));
-        response.addHeader("Date", formatDate(sixSecondsAgo));
+        response.addHeader("Date", DateUtils.formatStandardDate(now));
+        response.addHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo));
         Assert.assertFalse(policy.isResponseCacheable("GET", response));
     }
 
@@ -495,8 +491,8 @@ public class TestResponseCachingPolicy {
 
         request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
         response.setHeader("Cache-Control", "public");
-        response.addHeader("Date", formatDate(now));
-        response.addHeader("Date", formatDate(sixSecondsAgo));
+        response.addHeader("Date", DateUtils.formatStandardDate(now));
+        response.addHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo));
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
 
@@ -518,8 +514,8 @@ public class TestResponseCachingPolicy {
 
     @Test
     public void testResponsesWithMultipleExpiresHeadersAreNotCacheable() {
-        response.addHeader("Expires", formatDate(now));
-        response.addHeader("Expires", formatDate(sixSecondsAgo));
+        response.addHeader("Expires", DateUtils.formatStandardDate(now));
+        response.addHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
         Assert.assertFalse(policy.isResponseCacheable("GET", response));
     }
 
@@ -529,8 +525,8 @@ public class TestResponseCachingPolicy {
 
         request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
         response.setHeader("Cache-Control", "public");
-        response.addHeader("Expires", formatDate(now));
-        response.addHeader("Expires", formatDate(sixSecondsAgo));
+        response.addHeader("Expires", DateUtils.formatStandardDate(now));
+        response.addHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
 
@@ -591,8 +587,8 @@ public class TestResponseCachingPolicy {
     @Test
     public void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheable() {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
@@ -600,8 +596,8 @@ public class TestResponseCachingPolicy {
     public void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheable() {
         policy = new ResponseCachingPolicy(0, true, false, false);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
@@ -609,8 +605,8 @@ public class TestResponseCachingPolicy {
     public void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
         policy = new ResponseCachingPolicy(0, true, true, false);
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
@@ -618,8 +614,8 @@ public class TestResponseCachingPolicy {
     public void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
         policy = new ResponseCachingPolicy(0, true, true, false);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
@@ -662,8 +658,8 @@ public class TestResponseCachingPolicy {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
@@ -673,8 +669,8 @@ public class TestResponseCachingPolicy {
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
@@ -684,8 +680,8 @@ public class TestResponseCachingPolicy {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
 
@@ -695,8 +691,8 @@ public class TestResponseCachingPolicy {
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
 
@@ -717,8 +713,8 @@ public class TestResponseCachingPolicy {
     @Test
     public void getsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "1.0 someproxy");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -727,8 +723,8 @@ public class TestResponseCachingPolicy {
     public void headsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
         policy = new ResponseCachingPolicy(0, true, false, false);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "1.0 someproxy");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -737,8 +733,8 @@ public class TestResponseCachingPolicy {
     public void getsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
         policy = new ResponseCachingPolicy(0, true, true, true);
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "1.0 someproxy");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
@@ -747,8 +743,8 @@ public class TestResponseCachingPolicy {
     public void headsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
         policy = new ResponseCachingPolicy(0, true, true, true);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "1.0 someproxy");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
@@ -756,8 +752,8 @@ public class TestResponseCachingPolicy {
     @Test
     public void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "HTTP/1.0 someproxy");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -766,8 +762,8 @@ public class TestResponseCachingPolicy {
     public void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
         policy = new ResponseCachingPolicy(0, true, false, false);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "HTTP/1.0 someproxy");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -776,8 +772,8 @@ public class TestResponseCachingPolicy {
     public void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
         policy = new ResponseCachingPolicy(0, true, true, true);
         request = new BasicHttpRequest("GET", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "HTTP/1.0 someproxy");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
@@ -786,8 +782,8 @@ public class TestResponseCachingPolicy {
     public void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
         policy = new ResponseCachingPolicy(0, true, true, true);
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "HTTP/1.0 someproxy");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
@@ -797,8 +793,8 @@ public class TestResponseCachingPolicy {
         request = new BasicHttpRequest("GET", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "1.1 someproxy");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -809,24 +805,24 @@ public class TestResponseCachingPolicy {
         request = new BasicHttpRequest("HEAD", "/foo?s=bar");
         response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
         response.setVersion(HttpVersion.HTTP_1_0);
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(tenSecondsFromNow));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
         response.setHeader("Via", "1.1 someproxy");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
 
     @Test
     public void notCacheableIfExpiresEqualsDateAndNoCacheControl() {
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(now));
         response.removeHeaders("Cache-Control");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
 
     @Test
     public void notCacheableIfExpiresPrecedesDateAndNoCacheControl() {
-        response.setHeader("Date", formatDate(now));
-        response.setHeader("Expires", formatDate(sixSecondsAgo));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
+        response.setHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
         response.removeHeaders("Cache-Control");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
@@ -834,7 +830,7 @@ public class TestResponseCachingPolicy {
     @Test
     public void test302WithExplicitCachingHeaders() {
         response.setCode(HttpStatus.SC_MOVED_TEMPORARILY);
-        response.setHeader("Date", formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         response.setHeader("Cache-Control","max-age=300");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -843,7 +839,7 @@ public class TestResponseCachingPolicy {
     public void test303WithExplicitCachingHeadersUnderDefaultBehavior() {
         // RFC 2616 says: 303 should not be cached
         response.setCode(HttpStatus.SC_SEE_OTHER);
-        response.setHeader("Date", formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         response.setHeader("Cache-Control","max-age=300");
         Assert.assertFalse(policy.isResponseCacheable(request, response));
     }
@@ -854,7 +850,7 @@ public class TestResponseCachingPolicy {
         // response headers
         policy = new ResponseCachingPolicy(0, true, false, true);
         response.setCode(HttpStatus.SC_SEE_OTHER);
-        response.setHeader("Date", formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         response.setHeader("Cache-Control","max-age=300");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -862,7 +858,7 @@ public class TestResponseCachingPolicy {
     @Test
     public void test307WithExplicitCachingHeaders() {
         response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
-        response.setHeader("Date", formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         response.setHeader("Cache-Control","max-age=300");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
@@ -870,7 +866,7 @@ public class TestResponseCachingPolicy {
     @Test
     public void otherStatusCodesAreCacheableWithExplicitCachingHeaders() {
         response.setCode(HttpStatus.SC_NOT_FOUND);
-        response.setHeader("Date", formatDate(now));
+        response.setHeader("Date", DateUtils.formatStandardDate(now));
         response.setHeader("Cache-Control","max-age=300");
         Assert.assertTrue(policy.isResponseCacheable(request, response));
     }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
index fce3197..abef8e5 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
@@ -26,7 +26,7 @@
  */
 package org.apache.hc.client5.http.impl.cache;
 
-import java.util.Date;
+import java.time.Instant;
 
 import org.apache.hc.client5.http.ClientProtocolException;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
@@ -50,7 +50,7 @@ public class TestResponseProtocolCompliance {
     }
 
     private void setMinimalResponseHeaders(final HttpResponse resp) {
-        resp.setHeader("Date", DateUtils.formatDate(new Date()));
+        resp.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
         resp.setHeader("Server", "MyServer/1.0");
     }
 

[httpcomponents-client] 02/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 6cce8286b43cdf4b321adbdeb69ec6f9bac5dc2b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Nov 9 14:32:58 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, 554 insertions(+), 621 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..ebe121c 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,26 +319,20 @@ public class TestClientRequestExecution extends LocalServerTestBase {
             for (int i = 0; i < 20; i++) {
                 final HttpGet httpget = new HttpGet("/random/1000");
 
-                executorService.schedule(new Runnable() {
-
-                    @Override
-                    public void run() {
-                        httpget.cancel();
-                    }
-                }, rnd.nextInt(200), TimeUnit.MILLISECONDS);
+                executorService.schedule(httpget::cancel, rnd.nextInt(200), TimeUnit.MILLISECONDS);
 
-                try (final ClassicHttpResponse response = this.httpclient.execute(target, httpget)) {
+                this.httpclient.execute(target, httpget, response -> {
                     EntityUtils.consume(response.getEntity());
-                } catch (final Exception ignore) {
-                }
-
+                    return null;
+                });
             }
 
             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);