You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2022/09/26 18:32:14 UTC

[httpcomponents-client] branch master updated: Don't make loops and anonymous methods so verbose by using Java 8 features

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

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


The following commit(s) were added to refs/heads/master by this push:
     new bb67e4c0b Don't make loops and anonymous methods so verbose by using Java 8 features
bb67e4c0b is described below

commit bb67e4c0bee782316acc9e1f10660280f17f11d4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Sep 26 14:27:09 2022 -0400

    Don't make loops and anonymous methods so verbose by using Java 8
    features
    
    Document dependency bumps
---
 RELEASE_NOTES.txt                                  |  17 ++-
 .../hc/client5/testing/async/TestHttp1Async.java   |  16 +-
 .../client5/testing/sync/TestContentCodings.java   | 169 ++++++++-------------
 .../hc/client5/testing/sync/TestRedirects.java     |  31 ++--
 .../http/entity/mime/HttpRFC7578Multipart.java     |   3 +-
 .../hc/client5/http/entity/mime/MimeField.java     |   5 +-
 .../http/impl/async/H2AsyncClientBuilder.java      |   2 +-
 .../impl/async/H2AsyncClientProtocolStarter.java   |   8 +-
 .../HttpAsyncClientProtocolNegotiationStarter.java |  17 +--
 .../io/PoolingHttpClientConnectionManager.java     |   6 +-
 .../PoolingHttpClientConnectionManagerBuilder.java |   6 +-
 .../nio/PoolingAsyncClientConnectionManager.java   |   4 +-
 ...PoolingAsyncClientConnectionManagerBuilder.java |   4 +-
 .../client5/http/ssl/DefaultHostnameVerifier.java  |   9 +-
 .../client5/http/examples/ClientCustomContext.java |   4 +-
 .../hc/client5/http/examples/ClientFormLogin.java  |   8 +-
 .../http/examples/ClientWithRequestFuture.java     |   6 +-
 17 files changed, 123 insertions(+), 192 deletions(-)

diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 43de71565..2f23d1395 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,4 +1,19 @@
-Release 5.2 BETA1
+Release 5.2 BETA2
+------------------
+
+This is the second BETA release in the 5.2 release series that upgrades minimal JRE
+level to version 8 (8u251 is required) and includes several protocol level and
+API improvements. It also includes all bug fixes from the 5.1 branch.
+
+Notable changes and features included in the 5.2 series:
+
+* Bump junit-bom from 5.8.1 to 5.9.1 #379
+* Bump log4j.version from 2.17.2 to 2.19.0 #380
+* Bump ehcache-api from 3.9.6 to 3.10.1 #381
+* Bump jna.version from 5.9.0 to 5.12.1 #382
+
+
+Release 5.2 BETA1
 ------------------
 
 This is the first BETA release in the 5.2 release series that upgrades minimal JRE
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
index 0fdafe7a1..7c104f766 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
@@ -225,13 +225,7 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
                                 .setPath("/random/1000")
                                 .build(), null);
 
-                executorService.schedule(new Runnable() {
-
-                    @Override
-                    public void run() {
-                        future.cancel(true);
-                    }
-                }, i % 5, TimeUnit.MILLISECONDS);
+                executorService.schedule(() -> future.cancel(true), i % 5, TimeUnit.MILLISECONDS);
 
                 try {
                     future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
@@ -249,13 +243,7 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
                                 .setPath("/random/1000")
                                 .build(), null);
 
-                executorService.schedule(new Runnable() {
-
-                    @Override
-                    public void run() {
-                        future.cancel(true);
-                    }
-                }, rnd.nextInt(200), TimeUnit.MILLISECONDS);
+                executorService.schedule(() -> future.cancel(true), rnd.nextInt(200), TimeUnit.MILLISECONDS);
 
                 try {
                     future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
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 c303f56a9..3b3b9ece1 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
@@ -29,7 +29,6 @@ package org.apache.hc.client5.testing.sync;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -44,10 +43,7 @@ import java.util.zip.GZIPOutputStream;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.BasicHttpClientResponseHandler;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HeaderElement;
-import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.io.HttpRequestHandler;
@@ -55,7 +51,6 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.io.entity.InputStreamEntity;
 import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.MessageSupport;
-import org.apache.hc.core5.http.protocol.HttpContext;
 import org.junit.Test;
 import org.junit.jupiter.api.Assertions;
 
@@ -75,19 +70,7 @@ public class TestContentCodings extends LocalServerTestBase {
      */
     @Test
     public void testResponseWithNoContent() throws Exception {
-        this.server.registerHandler("*", new HttpRequestHandler() {
-
-            /**
-             * {@inheritDoc}
-             */
-            @Override
-            public void handle(
-                    final ClassicHttpRequest request,
-                    final ClassicHttpResponse response,
-                    final HttpContext context) throws HttpException, IOException {
-                response.setCode(HttpStatus.SC_NO_CONTENT);
-            }
-        });
+        this.server.registerHandler("*", (request, response, context) -> response.setCode(HttpStatus.SC_NO_CONTENT));
 
         final HttpHost target = start();
 
@@ -291,43 +274,33 @@ public class TestContentCodings extends LocalServerTestBase {
      */
     private HttpRequestHandler createDeflateEncodingRequestHandler(
             final String entityText, final boolean rfc1951) {
-        return new HttpRequestHandler() {
-
-            /**
-             * {@inheritDoc}
-             */
-            @Override
-            public void handle(
-                    final ClassicHttpRequest request,
-                    final ClassicHttpResponse response,
-                    final HttpContext context) throws HttpException, IOException {
-                response.setEntity(new StringEntity(entityText));
-                response.addHeader("Content-Type", "text/plain");
-                final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
-                while (it.hasNext()) {
-                    final HeaderElement element = it.next();
-                    if ("deflate".equalsIgnoreCase(element.getName())) {
-                        response.addHeader("Content-Encoding", "deflate");
-
-                            /* Gack. DeflaterInputStream is Java 6. */
-                        // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
-                        // ByteArrayInputStream(
-                        // entityText.getBytes("utf-8"))), -1));
-                        final byte[] uncompressed = entityText.getBytes(StandardCharsets.UTF_8);
-                        final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
-                        compressor.setInput(uncompressed);
-                        compressor.finish();
-                        final byte[] output = new byte[100];
-                        final int compressedLength = compressor.deflate(output);
-                        final byte[] compressed = new byte[compressedLength];
-                        System.arraycopy(output, 0, compressed, 0, compressedLength);
-                        response.setEntity(new InputStreamEntity(
-                                new ByteArrayInputStream(compressed), compressedLength, null));
-                        return;
-                    }
-                }
+        return (request, response, context) -> {
+            response.setEntity(new StringEntity(entityText));
+            response.addHeader("Content-Type", "text/plain");
+            final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
+            while (it.hasNext()) {
+        final HeaderElement element = it.next();
+        if ("deflate".equalsIgnoreCase(element.getName())) {
+            response.addHeader("Content-Encoding", "deflate");
+
+                /* Gack. DeflaterInputStream is Java 6. */
+            // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
+            // ByteArrayInputStream(
+            // entityText.getBytes("utf-8"))), -1));
+            final byte[] uncompressed = entityText.getBytes(StandardCharsets.UTF_8);
+            final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
+            compressor.setInput(uncompressed);
+            compressor.finish();
+            final byte[] output = new byte[100];
+            final int compressedLength = compressor.deflate(output);
+            final byte[] compressed = new byte[compressedLength];
+            System.arraycopy(output, 0, compressed, 0, compressedLength);
+            response.setEntity(new InputStreamEntity(
+                    new ByteArrayInputStream(compressed), compressedLength, null));
+            return;
+        }
             }
-        };
+         };
     }
 
     /**
@@ -339,57 +312,47 @@ public class TestContentCodings extends LocalServerTestBase {
      * @return a non-null {@link HttpRequestHandler}
      */
     private HttpRequestHandler createGzipEncodingRequestHandler(final String entityText) {
-        return new HttpRequestHandler() {
-
-            /**
-             * {@inheritDoc}
+        return (request, response, context) -> {
+            response.setEntity(new StringEntity(entityText));
+            response.addHeader("Content-Type", "text/plain");
+            response.addHeader("Content-Type", "text/plain");
+            final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
+            while (it.hasNext()) {
+        final HeaderElement element = it.next();
+        if ("gzip".equalsIgnoreCase(element.getName())) {
+            response.addHeader("Content-Encoding", "gzip");
+
+            /*
+             * We have to do a bit more work with gzip versus deflate, since
+             * Gzip doesn't appear to have an equivalent to DeflaterInputStream in
+             * the JDK.
+             *
+             * UPDATE: DeflaterInputStream is Java 6 anyway, so we have to do a bit
+             * of work there too!
              */
-            @Override
-            public void handle(
-                    final ClassicHttpRequest request,
-                    final ClassicHttpResponse response,
-                    final HttpContext context) throws HttpException, IOException {
-                response.setEntity(new StringEntity(entityText));
-                response.addHeader("Content-Type", "text/plain");
-                response.addHeader("Content-Type", "text/plain");
-                final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
-                while (it.hasNext()) {
-                    final HeaderElement element = it.next();
-                    if ("gzip".equalsIgnoreCase(element.getName())) {
-                        response.addHeader("Content-Encoding", "gzip");
-
-                        /*
-                         * We have to do a bit more work with gzip versus deflate, since
-                         * Gzip doesn't appear to have an equivalent to DeflaterInputStream in
-                         * the JDK.
-                         *
-                         * UPDATE: DeflaterInputStream is Java 6 anyway, so we have to do a bit
-                         * of work there too!
-                         */
-                        final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-                        final OutputStream out = new GZIPOutputStream(bytes);
-
-                        final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
-                                entityText.getBytes(StandardCharsets.UTF_8));
-
-                        final byte[] buf = new byte[60];
-
-                        int n;
-                        while ((n = uncompressed.read(buf)) != -1) {
-                            out.write(buf, 0, n);
-                        }
-
-                        out.close();
-
-                        final byte[] arr = bytes.toByteArray();
-                        response.setEntity(new InputStreamEntity(new ByteArrayInputStream(arr),
-                                arr.length, null));
-
-                        return;
-                    }
-                }
+            final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+            final OutputStream out = new GZIPOutputStream(bytes);
+
+            final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
+                    entityText.getBytes(StandardCharsets.UTF_8));
+
+            final byte[] buf = new byte[60];
+
+            int n;
+            while ((n = uncompressed.read(buf)) != -1) {
+                out.write(buf, 0, n);
+            }
+
+            out.close();
+
+            final byte[] arr = bytes.toByteArray();
+            response.setEntity(new InputStreamEntity(new ByteArrayInputStream(arr),
+                    arr.length, null));
+
+            return;
+        }
             }
-        };
+         };
     }
 
     /**
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 f2bf834d9..b57d9fca6 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.http.protocol.RedirectLocations;
 import org.apache.hc.client5.testing.OldPathRedirectResolver;
 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.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -57,7 +56,6 @@ import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.ProtocolException;
-import org.apache.hc.core5.http.io.HttpServerRequestHandler;
 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.BasicHeader;
@@ -509,26 +507,19 @@ public class TestRedirects extends LocalServerTestBase {
     @Test
     public void testCompressionHeaderRedirect() throws Exception {
         final Queue<String> values = new ConcurrentLinkedQueue<>();
-        final HttpHost target = start(null, new Decorator<HttpServerRequestHandler>() {
+        final HttpHost target = start(null, requestHandler -> new RedirectingDecorator(
+                requestHandler,
+                new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_TEMPORARILY)) {
 
             @Override
-            public HttpServerRequestHandler decorate(final HttpServerRequestHandler requestHandler) {
-                return new RedirectingDecorator(
-                        requestHandler,
-                        new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_TEMPORARILY)) {
-
-                    @Override
-                    public void handle(final ClassicHttpRequest request,
-                                       final ResponseTrigger responseTrigger,
-                                       final HttpContext context) throws HttpException, IOException {
-                        final Header header = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
-                        if (header != null) {
-                            values.add(header.getValue());
-                        }
-                        super.handle(request, responseTrigger, context);
-                    }
-
-                };
+            public void handle(final ClassicHttpRequest request,
+                               final ResponseTrigger responseTrigger,
+                               final HttpContext context) throws HttpException, IOException {
+                final Header header = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
+                if (header != null) {
+                    values.add(header.getValue());
+                }
+                super.handle(request, responseTrigger, context);
             }
 
         });
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
index 64407f08f..a02194866 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
@@ -66,8 +66,7 @@ class HttpRFC7578Multipart extends AbstractMultipartFormat {
                 writeBytes(FIELD_SEP, out);
                 writeBytes(field.getValue(), out);
                 final List<NameValuePair> parameters = field.getParameters();
-                for (int i = 0; i < parameters.size(); i++) {
-                    final NameValuePair parameter = parameters.get(i);
+                for (final NameValuePair parameter : parameters) {
                     final String name = parameter.getName();
                     final String value = parameter.getValue();
                     writeBytes("; ", out);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
index 87e9e9620..13b4d74c7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
@@ -79,14 +79,13 @@ public class MimeField {
     public String getBody() {
         final StringBuilder sb = new StringBuilder();
         sb.append(this.value);
-        for (int i = 0; i < this.parameters.size(); i++) {
-            final NameValuePair parameter = this.parameters.get(i);
+        this.parameters.forEach(parameter -> {
             sb.append("; ");
             sb.append(parameter.getName());
             sb.append("=\"");
             sb.append(parameter.getValue());
             sb.append("\"");
-        }
+        });
         return sb.toString();
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java
index 3cdc556ee..aaf2dcb2e 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java
@@ -559,7 +559,7 @@ public class H2AsyncClientBuilder {
      * @since 5.2
      */
     public final H2AsyncClientBuilder setDefaultConnectionConfig(final ConnectionConfig connectionConfig) {
-        this.connectionConfigResolver = (host) -> connectionConfig;
+        this.connectionConfigResolver = host -> connectionConfig;
         return this;
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientProtocolStarter.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientProtocolStarter.java
index 11137fa5e..a688846ea 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientProtocolStarter.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientProtocolStarter.java
@@ -113,18 +113,14 @@ class H2AsyncClientProtocolStarter implements IOEventHandlerFactory {
                         @Override
                         public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
                             if (HEADER_LOG.isDebugEnabled()) {
-                                for (int i = 0; i < headers.size(); i++) {
-                                    HEADER_LOG.debug("{} << {}", id, headers.get(i));
-                                }
+                                headers.forEach(header -> HEADER_LOG.debug("{} << {}", id, header));
                             }
                         }
 
                         @Override
                         public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
                             if (HEADER_LOG.isDebugEnabled()) {
-                                for (int i = 0; i < headers.size(); i++) {
-                                    HEADER_LOG.debug("{} >> {}", id, headers.get(i));
-                                }
+                                headers.forEach(header -> HEADER_LOG.debug("{} >> {}", id, header));
                             }
                         }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientProtocolNegotiationStarter.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientProtocolNegotiationStarter.java
index 68e617a43..537ecefff 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientProtocolNegotiationStarter.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientProtocolNegotiationStarter.java
@@ -28,7 +28,6 @@
 package org.apache.hc.client5.http.impl.async;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.hc.client5.http.impl.DefaultClientConnectionReuseStrategy;
@@ -127,9 +126,7 @@ class HttpAsyncClientProtocolNegotiationStarter implements IOEventHandlerFactory
                         public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
                             if (HEADER_LOG.isDebugEnabled()) {
                                 HEADER_LOG.debug("{} >> {}", id, new RequestLine(request));
-                                for (final Iterator<Header> it = request.headerIterator(); it.hasNext(); ) {
-                                    HEADER_LOG.debug("{} >> {}", id, it.next());
-                                }
+                                request.headerIterator().forEachRemaining(header -> HEADER_LOG.debug("{} >> {}", id, header));
                             }
                         }
 
@@ -137,9 +134,7 @@ class HttpAsyncClientProtocolNegotiationStarter implements IOEventHandlerFactory
                         public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
                             if (HEADER_LOG.isDebugEnabled()) {
                                 HEADER_LOG.debug("{} << {}", id, new StatusLine(response));
-                                for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
-                                    HEADER_LOG.debug("{} << {}", id, it.next());
-                                }
+                                response.headerIterator().forEachRemaining(header -> HEADER_LOG.debug("{} << {}", id, header));
                             }
                         }
 
@@ -189,18 +184,14 @@ class HttpAsyncClientProtocolNegotiationStarter implements IOEventHandlerFactory
                         @Override
                         public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
                             if (HEADER_LOG.isDebugEnabled()) {
-                                for (int i = 0; i < headers.size(); i++) {
-                                    HEADER_LOG.debug("{} << {}", id, headers.get(i));
-                                }
+                                headers.forEach(header -> HEADER_LOG.debug("{} << {}", id, header));
                             }
                         }
 
                         @Override
                         public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
                             if (HEADER_LOG.isDebugEnabled()) {
-                                for (int i = 0; i < headers.size(); i++) {
-                                    HEADER_LOG.debug("{} >> {}", id, headers.get(i));
-                                }
+                                headers.forEach(header -> HEADER_LOG.debug("{} >> {}", id, header));
                             }
                         }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
index 953be5f2f..2763045f1 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
@@ -522,7 +522,7 @@ public class PoolingHttpClientConnectionManager
      * Sets the same {@link SocketConfig} for all routes
      */
     public void setDefaultSocketConfig(final SocketConfig config) {
-        this.socketConfigResolver = (route) -> config;
+        this.socketConfigResolver = route -> config;
     }
 
     /**
@@ -540,7 +540,7 @@ public class PoolingHttpClientConnectionManager
      * @since 5.2
      */
     public void setDefaultConnectionConfig(final ConnectionConfig config) {
-        this.connectionConfigResolver = (route) -> config;
+        this.connectionConfigResolver = route -> config;
     }
 
     /**
@@ -558,7 +558,7 @@ public class PoolingHttpClientConnectionManager
      * @since 5.2
      */
     public void setDefaultTlsConfig(final TlsConfig config) {
-        this.tlsConfigResolver = (host) -> config;
+        this.tlsConfigResolver = host -> config;
     }
 
     /**
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
index 799c6ba86..168d43043 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
@@ -168,7 +168,7 @@ public class PoolingHttpClientConnectionManagerBuilder {
      * Assigns the same {@link SocketConfig} for all routes.
      */
     public final PoolingHttpClientConnectionManagerBuilder setDefaultSocketConfig(final SocketConfig config) {
-        this.socketConfigResolver = (route) -> config;
+        this.socketConfigResolver = route -> config;
         return this;
     }
 
@@ -189,7 +189,7 @@ public class PoolingHttpClientConnectionManagerBuilder {
      * @since 5.2
      */
     public final PoolingHttpClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
-        this.connectionConfigResolver = (route) -> config;
+        this.connectionConfigResolver = route -> config;
         return this;
     }
 
@@ -210,7 +210,7 @@ public class PoolingHttpClientConnectionManagerBuilder {
      * @since 5.2
      */
     public final PoolingHttpClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) {
-        this.tlsConfigResolver = (host) -> config;
+        this.tlsConfigResolver = host -> config;
         return this;
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
index 08758fc27..483b094c2 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
@@ -588,7 +588,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
      * @since 5.2
      */
     public void setDefaultConnectionConfig(final ConnectionConfig config) {
-        this.connectionConfigResolver = (route) -> config;
+        this.connectionConfigResolver = route -> config;
     }
 
     /**
@@ -606,7 +606,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
      * @since 5.2
      */
     public void setDefaultTlsConfig(final TlsConfig config) {
-        this.tlsConfigResolver = (host) -> config;
+        this.tlsConfigResolver = host -> config;
     }
 
     /**
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
index 302e5af96..90ff95a34 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
@@ -159,7 +159,7 @@ public class PoolingAsyncClientConnectionManagerBuilder {
      * @since 5.2
      */
     public final PoolingAsyncClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
-        this.connectionConfigResolver = (route) -> config;
+        this.connectionConfigResolver = route -> config;
         return this;
     }
 
@@ -180,7 +180,7 @@ public class PoolingAsyncClientConnectionManagerBuilder {
      * @since 5.2
      */
     public final PoolingAsyncClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) {
-        this.tlsConfigResolver = (host) -> config;
+        this.tlsConfigResolver = host -> config;
         return this;
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java
index 2c030ac9d..3c56ac939 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java
@@ -123,8 +123,7 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
     }
 
     static void matchIPAddress(final String host, final List<SubjectName> subjectAlts) throws SSLException {
-        for (int i = 0; i < subjectAlts.size(); i++) {
-            final SubjectName subjectAlt = subjectAlts.get(i);
+        for (final SubjectName subjectAlt : subjectAlts) {
             if (subjectAlt.getType() == SubjectName.IP) {
                 if (host.equals(subjectAlt.getValue())) {
                     return;
@@ -137,8 +136,7 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
 
     static void matchIPv6Address(final String host, final List<SubjectName> subjectAlts) throws SSLException {
         final String normalisedHost = normaliseAddress(host);
-        for (int i = 0; i < subjectAlts.size(); i++) {
-            final SubjectName subjectAlt = subjectAlts.get(i);
+        for (final SubjectName subjectAlt : subjectAlts) {
             if (subjectAlt.getType() == SubjectName.IP) {
                 final String normalizedSubjectAlt = normaliseAddress(subjectAlt.getValue());
                 if (normalisedHost.equals(normalizedSubjectAlt)) {
@@ -153,8 +151,7 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
     static void matchDNSName(final String host, final List<SubjectName> subjectAlts,
                              final PublicSuffixMatcher publicSuffixMatcher) throws SSLException {
         final String normalizedHost = DnsUtils.normalize(host);
-        for (int i = 0; i < subjectAlts.size(); i++) {
-            final SubjectName subjectAlt = subjectAlts.get(i);
+        for (final SubjectName subjectAlt : subjectAlts) {
             if (subjectAlt.getType() == SubjectName.DNS) {
                 final String normalizedSubjectAlt = DnsUtils.normalize(subjectAlt.getValue());
                 if (matchIdentityStrict(normalizedHost, normalizedSubjectAlt, publicSuffixMatcher)) {
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 dff858631..ce93914f8 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
@@ -65,9 +65,7 @@ public class ClientCustomContext {
                 System.out.println("----------------------------------------");
                 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));
-                }
+                cookies.forEach(element -> System.out.println("Local cookie: " + element));
                 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 0a580adb0..3f9e90a67 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
@@ -60,9 +60,7 @@ public class ClientFormLogin {
                 if (cookies.isEmpty()) {
                     System.out.println("None");
                 } else {
-                    for (int i = 0; i < cookies.size(); i++) {
-                        System.out.println("- " + cookies.get(i));
-                    }
+                    cookies.forEach(element -> System.out.println("- " + element));
                 }
                 return null;
             });
@@ -82,9 +80,7 @@ public class ClientFormLogin {
                 if (cookies.isEmpty()) {
                     System.out.println("None");
                 } else {
-                    for (int i = 0; i < cookies.size(); i++) {
-                        System.out.println("- " + cookies.get(i));
-                    }
+                    cookies.forEach(element -> System.out.println("- " + element));
                 }
                 return null;
             });
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java
index 0f3b3aaa7..219fef943 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java
@@ -58,10 +58,8 @@ public class ClientWithRequestFuture {
         try (final FutureRequestExecutionService requestExecService = new FutureRequestExecutionService(
                 httpclient, execService)) {
             // Because things are asynchronous, you must provide a HttpClientResponseHandler
-            final HttpClientResponseHandler<Boolean> handler = response -> {
-                // simply return true if the status was OK
-                return response.getCode() == HttpStatus.SC_OK;
-            };
+            // simply return true if the status was OK
+            final HttpClientResponseHandler<Boolean> handler = response -> response.getCode() == HttpStatus.SC_OK;
 
             // Simple request ...
             final HttpGet request1 = new HttpGet("http://httpbin.org/get");