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 2023/12/13 08:23:40 UTC

(httpcomponents-core) 13/37: Async requesters to populate request URI authority based on the target host when not explicitly set by the caller

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-core.git

commit 600fa3d2572a752a0641685903accc4c10a4a93b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Aug 28 12:53:39 2023 +0200

    Async requesters to populate request URI authority based on the target host when not explicitly set by the caller
---
 .../hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java    | 4 ++++
 .../org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java   | 4 ++++
 .../java/org/apache/hc/core5/http/examples/AsyncClientSNIExample.java | 1 -
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java
index e9199cbba..eeda4ae6f 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java
@@ -66,6 +66,7 @@ import org.apache.hc.core5.http.nio.support.BasicClientExchangeHandler;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http2.nio.pool.H2ConnPool;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
@@ -173,6 +174,9 @@ public class H2MultiplexingRequester extends AsyncRequester{
         try {
             exchangeHandler.produceRequest((request, entityDetails, httpContext) -> {
                 final HttpHost host = target != null ? target : defaultTarget(request);
+                if (request.getAuthority() == null) {
+                    request.setAuthority(new URIAuthority(host.getHostName(), host.getPort()));
+                }
                 connPool.getSession(host, timeout, new FutureCallback<IOSession>() {
 
                     @Override
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index 2f1afe7c8..a3b0d2fa8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -68,6 +68,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.io.CloseMode;
 import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.pool.ManagedConnPool;
 import org.apache.hc.core5.pool.PoolEntry;
@@ -287,6 +288,9 @@ public class HttpAsyncRequester extends AsyncRequester implements ConnPoolContro
         try {
             exchangeHandler.produceRequest((request, entityDetails, requestContext) -> {
                 final HttpHost host = target != null ? target : defaultTarget(request);
+                if (request.getAuthority() == null) {
+                    request.setAuthority(new URIAuthority(host.getHostName(), host.getPort()));
+                }
                 connect(host, timeout, null, new FutureCallback<AsyncClientEndpoint>() {
 
                     @Override
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncClientSNIExample.java b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncClientSNIExample.java
index 706d327db..90a033cc9 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncClientSNIExample.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncClientSNIExample.java
@@ -105,7 +105,6 @@ public class AsyncClientSNIExample {
 
         final CountDownLatch latch = new CountDownLatch(1);
         final HttpRequest request = BasicRequestBuilder.get()
-                .setHttpHost(target)
                 .setPath("/")
                 .build();
         requester.execute(