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 2022/09/04 10:42:49 UTC

[httpcomponents-client] 01/01: HTTPCLIENT-2232: last protocol interceptrs moved at the end of the H2 protocol processing pipeline

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

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

commit bfb8ec2d7e22c065d008f814b1b8309f2516bd89
Author: Oleg Kalnichevski <Ol...@abraxas.ch>
AuthorDate: Sun Sep 4 12:40:20 2022 +0200

    HTTPCLIENT-2232: last protocol interceptrs moved at the end of the H2 protocol processing pipeline
---
 .../http/impl/async/H2AsyncClientBuilder.java      | 61 +++++++++++-----------
 .../http/impl/async/HttpAsyncClientBuilder.java    | 60 +++++++++++----------
 2 files changed, 62 insertions(+), 59 deletions(-)

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 8a0f82afa..bdce7e445 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
@@ -27,25 +27,14 @@
 
 package org.apache.hc.client5.http.impl.async;
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ThreadFactory;
-
 import org.apache.hc.client5.http.AuthenticationStrategy;
 import org.apache.hc.client5.http.DnsResolver;
 import org.apache.hc.client5.http.HttpRequestRetryStrategy;
 import org.apache.hc.client5.http.SchemePortResolver;
 import org.apache.hc.client5.http.async.AsyncExecChainHandler;
 import org.apache.hc.client5.http.auth.AuthSchemeFactory;
-import org.apache.hc.client5.http.auth.StandardAuthScheme;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
+import org.apache.hc.client5.http.auth.StandardAuthScheme;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.cookie.BasicCookieStore;
 import org.apache.hc.client5.http.cookie.CookieSpecFactory;
@@ -93,7 +82,6 @@ import org.apache.hc.core5.http.nio.command.ShutdownCommand;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
 import org.apache.hc.core5.http.protocol.RequestTargetHost;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
@@ -112,6 +100,17 @@ import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.VersionInfo;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ThreadFactory;
+
 /**
  * Builder for HTTP/2 only {@link CloseableHttpAsyncClient} instances.
  * <p>
@@ -656,24 +655,9 @@ public class H2AsyncClientBuilder {
         if (!cookieManagementDisabled) {
             b.add(new ResponseProcessCookies());
         }
-        if (requestInterceptors != null) {
-            for (final RequestInterceptorEntry entry: requestInterceptors) {
-                if (entry.position == RequestInterceptorEntry.Position.LAST) {
-                    b.addLast(entry.interceptor);
-                }
-            }
-        }
-        if (responseInterceptors != null) {
-            for (final ResponseInterceptorEntry entry: responseInterceptors) {
-                if (entry.position == ResponseInterceptorEntry.Position.LAST) {
-                    b.addLast(entry.interceptor);
-                }
-            }
-        }
 
-        final HttpProcessor httpProcessor = b.build();
         execChainDefinition.addFirst(
-                new AsyncProtocolExec(httpProcessor, targetAuthStrategyCopy, proxyAuthStrategyCopy, schemePortResolver),
+                new AsyncProtocolExec(b.build(), targetAuthStrategyCopy, proxyAuthStrategyCopy, schemePortResolver),
                 ChainElement.PROTOCOL.name());
 
         // Add request retry executor, if not disabled
@@ -707,9 +691,26 @@ public class H2AsyncClientBuilder {
                     ChainElement.REDIRECT.name());
         }
 
+        final HttpProcessorBuilder b2 = HttpProcessorBuilder.create();
+        b2.addAll(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl());
+        if (requestInterceptors != null) {
+            for (final RequestInterceptorEntry entry: requestInterceptors) {
+                if (entry.position == RequestInterceptorEntry.Position.LAST) {
+                    b2.addLast(entry.interceptor);
+                }
+            }
+        }
+        if (responseInterceptors != null) {
+            for (final ResponseInterceptorEntry entry: responseInterceptors) {
+                if (entry.position == ResponseInterceptorEntry.Position.LAST) {
+                    b2.addLast(entry.interceptor);
+                }
+            }
+        }
+
         final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
         final IOEventHandlerFactory ioEventHandlerFactory = new H2AsyncClientEventHandlerFactory(
-                new DefaultHttpProcessor(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl()),
+                b2.build(),
                 new HandlerFactory<AsyncPushConsumer>() {
 
                     @Override
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
index 6a8384916..fc80c8025 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
@@ -27,17 +27,6 @@
 
 package org.apache.hc.client5.http.impl.async;
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.net.ProxySelector;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ThreadFactory;
-
 import org.apache.hc.client5.http.AuthenticationStrategy;
 import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
 import org.apache.hc.client5.http.HttpRequestRetryStrategy;
@@ -102,7 +91,6 @@ import org.apache.hc.core5.http.nio.HandlerFactory;
 import org.apache.hc.core5.http.nio.command.ShutdownCommand;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
 import org.apache.hc.core5.http.protocol.RequestTargetHost;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
@@ -122,6 +110,17 @@ import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.VersionInfo;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.net.ProxySelector;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ThreadFactory;
+
 /**
  * Builder for {@link CloseableHttpAsyncClient} instances that can negotiate
  * the most optimal HTTP protocol version during the {@code TLS} handshake
@@ -817,24 +816,9 @@ public class HttpAsyncClientBuilder {
         if (!cookieManagementDisabled) {
             b.add(new ResponseProcessCookies());
         }
-        if (requestInterceptors != null) {
-            for (final RequestInterceptorEntry entry: requestInterceptors) {
-                if (entry.position == RequestInterceptorEntry.Position.LAST) {
-                    b.addLast(entry.interceptor);
-                }
-            }
-        }
-        if (responseInterceptors != null) {
-            for (final ResponseInterceptorEntry entry: responseInterceptors) {
-                if (entry.position == ResponseInterceptorEntry.Position.LAST) {
-                    b.addLast(entry.interceptor);
-                }
-            }
-        }
 
-        final HttpProcessor httpProcessor = b.build();
         execChainDefinition.addFirst(
-                new AsyncProtocolExec(httpProcessor, targetAuthStrategyCopy, proxyAuthStrategyCopy, schemePortResolver),
+                new AsyncProtocolExec(b.build(), targetAuthStrategyCopy, proxyAuthStrategyCopy, schemePortResolver),
                 ChainElement.PROTOCOL.name());
 
         // Add request retry executor, if not disabled
@@ -922,9 +906,27 @@ public class HttpAsyncClientBuilder {
                 reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;
             }
         }
+
+        final HttpProcessorBuilder b2 = HttpProcessorBuilder.create();
+        b2.addAll(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl());
+        if (requestInterceptors != null) {
+            for (final RequestInterceptorEntry entry: requestInterceptors) {
+                if (entry.position == RequestInterceptorEntry.Position.LAST) {
+                    b2.addLast(entry.interceptor);
+                }
+            }
+        }
+        if (responseInterceptors != null) {
+            for (final ResponseInterceptorEntry entry: responseInterceptors) {
+                if (entry.position == ResponseInterceptorEntry.Position.LAST) {
+                    b2.addLast(entry.interceptor);
+                }
+            }
+        }
+
         final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
         final IOEventHandlerFactory ioEventHandlerFactory = new HttpAsyncClientEventHandlerFactory(
-                new DefaultHttpProcessor(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl()),
+                b2.build(),
                 new HandlerFactory<AsyncPushConsumer>() {
 
                     @Override