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 2017/10/25 14:58:48 UTC

[1/3] httpcomponents-core git commit: HTTPCLIENT-1876: Improve the buildString() method in URIBuilder

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 29d31f9f1 -> aabcf7544


HTTPCLIENT-1876: Improve the buildString() method in URIBuilder


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/d4df4167
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/d4df4167
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/d4df4167

Branch: refs/heads/master
Commit: d4df416742454881817cdf5d9e65a6760736aa16
Parents: 29d31f9
Author: aleh_struneuski <al...@epam.com>
Authored: Wed Oct 25 12:26:15 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Oct 25 12:26:15 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/net/URIBuilder.java   |  2 +-
 .../org/apache/hc/core5/net/TestURIBuilder.java    | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d4df4167/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
index 19dce56..89ef6df 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
@@ -171,7 +171,7 @@ public class URIBuilder {
             }
             if (this.encodedQuery != null) {
                 sb.append("?").append(this.encodedQuery);
-            } else if (this.queryParams != null) {
+            } else if (this.queryParams != null && !this.queryParams.isEmpty()) {
                 sb.append("?").append(encodeUrlForm(this.queryParams));
             } else if (this.query != null) {
                 sb.append("?").append(encodeUric(this.query));

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d4df4167/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
index 2929f55..ae376b1 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
@@ -32,6 +32,7 @@ import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.hc.core5.http.NameValuePair;
@@ -186,6 +187,22 @@ public class TestURIBuilder {
     }
 
     @Test
+    public void testSetParametersWithEmptyArg() throws Exception {
+        final URI uri = new URI("http", null, "localhost", 80, "/test", "param=test", null);
+        final URIBuilder uribuilder = new URIBuilder(uri).setParameters();
+        final URI result = uribuilder.build();
+        Assert.assertEquals(new URI("http://localhost:80/test"), result);
+    }
+
+    @Test
+    public void testSetParametersWithEmptyList() throws Exception {
+        final URI uri = new URI("http", null, "localhost", 80, "/test", "param=test", null);
+        final URIBuilder uribuilder = new URIBuilder(uri).setParameters(Arrays.<NameValuePair>asList());
+        final URI result = uribuilder.build();
+        Assert.assertEquals(new URI("http://localhost:80/test"), result);
+    }
+
+    @Test
     public void testParameterWithSpecialChar() throws Exception {
         final URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
         final URIBuilder uribuilder = new URIBuilder(uri).addParameter("param", "1 + 1 = 2")


[2/3] httpcomponents-core git commit: Added functional Transformation and Resolver interfaces

Posted by ol...@apache.org.
Added functional Transformation and Resolver interfaces


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/a3f112ae
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/a3f112ae
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/a3f112ae

Branch: refs/heads/master
Commit: a3f112ae93c9f37be75978d74c463cdeb58b267b
Parents: d4df416
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Oct 24 13:31:01 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Oct 25 13:01:35 2017 +0200

----------------------------------------------------------------------
 .../org/apache/hc/core5/function/Resolver.java  | 39 ++++++++++++++++++++
 .../hc/core5/function/Transformation.java       | 39 ++++++++++++++++++++
 2 files changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a3f112ae/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java
new file mode 100644
index 0000000..3cb42f4
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java
@@ -0,0 +1,39 @@
+/*
+ * ====================================================================
+ * 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.core5.function;
+
+/**
+ * Abstract resolver from input to output.
+ *
+ * @since 5.0
+ */
+public interface Resolver<I, O> {
+
+    O resolve(I object);
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a3f112ae/httpcore5/src/main/java/org/apache/hc/core5/function/Transformation.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Transformation.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Transformation.java
new file mode 100644
index 0000000..84da663
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Transformation.java
@@ -0,0 +1,39 @@
+/*
+ * ====================================================================
+ * 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.core5.function;
+
+/**
+ * Abstract transformation from input to output.
+ *
+ * @since 5.0
+ */
+public interface Transformation<I, O> {
+
+    O transform(I object);
+
+}


[3/3] httpcomponents-core git commit: Added default HttpHost to InetSocketAddress resolver

Posted by ol...@apache.org.
Added default HttpHost to InetSocketAddress resolver


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/aabcf754
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/aabcf754
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/aabcf754

Branch: refs/heads/master
Commit: aabcf75442080ce915a566011cb26e92068b3658
Parents: a3f112a
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Oct 25 13:19:51 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Oct 25 13:19:51 2017 +0200

----------------------------------------------------------------------
 .../testing/classic/ClassicTestClient.java      |  4 +-
 .../core5/http/impl/DefaultAddressResolver.java | 58 ++++++++++++++++++++
 .../http/impl/bootstrap/AsyncRequester.java     | 24 +++-----
 .../http/impl/bootstrap/HttpAsyncRequester.java |  3 +-
 .../http/impl/bootstrap/HttpRequester.java      | 28 +++-------
 .../http/impl/bootstrap/RequesterBootstrap.java |  4 +-
 6 files changed, 82 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aabcf754/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
index 8d7c799..fc81197 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
@@ -41,6 +41,7 @@ import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.HttpProcessors;
+import org.apache.hc.core5.http.impl.DefaultAddressResolver;
 import org.apache.hc.core5.http.impl.bootstrap.HttpRequester;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnectionFactory;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
@@ -97,7 +98,8 @@ public class ClassicTestClient {
                     connPool,
                     socketConfig,
                     new DefaultBHttpClientConnectionFactory(H1Config.DEFAULT, CharCodingConfig.DEFAULT),
-                    sslContext != null ? sslContext.getSocketFactory() : null);
+                    sslContext != null ? sslContext.getSocketFactory() : null,
+                    DefaultAddressResolver.INSTANCE);
             requesterRef.compareAndSet(null, requester);
         } else {
             throw new IllegalStateException("Requester has already been started");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aabcf754/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultAddressResolver.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultAddressResolver.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultAddressResolver.java
new file mode 100644
index 0000000..e1563d3
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultAddressResolver.java
@@ -0,0 +1,58 @@
+/*
+ * ====================================================================
+ * 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.core5.http.impl;
+
+import java.net.InetSocketAddress;
+
+import org.apache.hc.core5.function.Resolver;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
+
+public final class DefaultAddressResolver implements Resolver<HttpHost, InetSocketAddress> {
+
+    public static final DefaultAddressResolver INSTANCE = new DefaultAddressResolver();
+
+    @Override
+    public InetSocketAddress resolve(final HttpHost host) {
+        if (host == null) {
+            return null;
+        }
+        int port = host.getPort();
+        if (port < 0) {
+            final String scheme = host.getSchemeName();
+            if (URIScheme.HTTP.same(scheme)) {
+                port = 80;
+            } else if (URIScheme.HTTPS.same(scheme)) {
+                port = 443;
+            }
+        }
+        final String hostName = host.getHostName();
+        return new InetSocketAddress(hostName, port);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aabcf754/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
index c0270c1..5336ca5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
@@ -37,8 +37,9 @@ import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Decorator;
+import org.apache.hc.core5.function.Resolver;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.impl.DefaultAddressResolver;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ConnectionInitiator;
@@ -56,13 +57,15 @@ import org.apache.hc.core5.util.TimeValue;
 public class AsyncRequester implements IOReactorService, ConnectionInitiator {
 
     private final DefaultConnectingIOReactor ioReactor;
+    private final Resolver<HttpHost, InetSocketAddress> addressResolver;
 
     public AsyncRequester(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
             final Decorator<IOSession> ioSessionDecorator,
             final IOSessionListener sessionListener,
-            final Callback<IOSession> sessionShutdownCallback) {
+            final Callback<IOSession> sessionShutdownCallback,
+            final Resolver<HttpHost, InetSocketAddress> addressResolver) {
         this.ioReactor = new DefaultConnectingIOReactor(
                 eventHandlerFactory,
                 ioReactorConfig,
@@ -70,20 +73,7 @@ public class AsyncRequester implements IOReactorService, ConnectionInitiator {
                 ioSessionDecorator,
                 sessionListener,
                 sessionShutdownCallback);
-    }
-
-    private InetSocketAddress toSocketAddress(final HttpHost host) {
-        int port = host.getPort();
-        if (port < 0) {
-            final String scheme = host.getSchemeName();
-            if (URIScheme.HTTP.same(scheme)) {
-                port = 80;
-            } else if (URIScheme.HTTPS.same(scheme)) {
-                port = 443;
-            }
-        }
-        final String hostName = host.getHostName();
-        return new InetSocketAddress(hostName, port);
+        this.addressResolver = addressResolver != null ? addressResolver : DefaultAddressResolver.INSTANCE;
     }
 
     @Override
@@ -104,7 +94,7 @@ public class AsyncRequester implements IOReactorService, ConnectionInitiator {
             final FutureCallback<IOSession> callback) {
         Args.notNull(host, "Host");
         Args.notNull(timeout, "Timeout");
-        return connect(host, toSocketAddress(host), null, timeout, attachment, callback);
+        return connect(host, addressResolver.resolve(host), null, timeout, attachment, callback);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aabcf754/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
----------------------------------------------------------------------
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 0b4e0d2..e6de70b 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
@@ -47,6 +47,7 @@ import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.impl.DefaultAddressResolver;
 import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
@@ -97,7 +98,7 @@ public class HttpAsyncRequester extends AsyncRequester implements ConnPoolContro
                 session.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
             }
 
-        });
+        }, DefaultAddressResolver.INSTANCE);
         this.connPool = Args.notNull(connPool, "Connection pool");
         this.tlsStrategy = tlsStrategy;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aabcf754/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
index 65dac19..c02d297 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
@@ -40,6 +40,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import javax.net.ssl.SSLSocketFactory;
 
+import org.apache.hc.core5.function.Resolver;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -51,6 +52,7 @@ import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.SocketConfig;
+import org.apache.hc.core5.http.impl.DefaultAddressResolver;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnectionFactory;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
 import org.apache.hc.core5.http.io.EofSensorInputStream;
@@ -85,6 +87,7 @@ public class HttpRequester implements ConnPoolControl<HttpHost>, GracefullyClose
     private final SocketConfig socketConfig;
     private final HttpConnectionFactory<? extends HttpClientConnection> connectFactory;
     private final SSLSocketFactory sslSocketFactory;
+    private final Resolver<HttpHost, InetSocketAddress> addressResolver;
 
     public HttpRequester(
             final HttpRequestExecutor requestExecutor,
@@ -92,7 +95,8 @@ public class HttpRequester implements ConnPoolControl<HttpHost>, GracefullyClose
             final ManagedConnPool<HttpHost, HttpClientConnection> connPool,
             final SocketConfig socketConfig,
             final HttpConnectionFactory<? extends HttpClientConnection> connectFactory,
-            final SSLSocketFactory sslSocketFactory) {
+            final SSLSocketFactory sslSocketFactory,
+            final Resolver<HttpHost, InetSocketAddress> addressResolver) {
         this.requestExecutor = Args.notNull(requestExecutor, "Request executor");
         this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
         this.connPool = Args.notNull(connPool, "Connection pool");
@@ -100,6 +104,7 @@ public class HttpRequester implements ConnPoolControl<HttpHost>, GracefullyClose
         this.connectFactory = connectFactory != null ? connectFactory : new DefaultBHttpClientConnectionFactory(
                 H1Config.DEFAULT, CharCodingConfig.DEFAULT);
         this.sslSocketFactory = sslSocketFactory != null ? sslSocketFactory : (SSLSocketFactory) SSLSocketFactory.getDefault();
+        this.addressResolver = addressResolver != null ? addressResolver : DefaultAddressResolver.INSTANCE;
     }
 
     @Override
@@ -229,25 +234,10 @@ public class HttpRequester implements ConnPoolControl<HttpHost>, GracefullyClose
             sock.setSoLinger(true, linger);
         }
 
-        final String scheme = targetHost.getSchemeName();
-        int port = targetHost.getPort();
-        if (port < 0) {
-            if (URIScheme.HTTP.same(scheme)) {
-                port = 80;
-            } else if (URIScheme.HTTPS.same(scheme)) {
-                port = 443;
-            }
-        }
-        final InetSocketAddress targetAddress;
-        if (targetHost.getAddress() != null) {
-            targetAddress = new InetSocketAddress(targetHost.getAddress(), port);
-        } else {
-            targetAddress = new InetSocketAddress(targetHost.getHostName(), port);
-        }
+        final InetSocketAddress targetAddress = addressResolver.resolve(targetHost);
         sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound());
-
-        if (URIScheme.HTTPS.same(scheme)) {
-            return sslSocketFactory.createSocket(sock, targetHost.getHostName(), port, true);
+        if (URIScheme.HTTPS.same(targetHost.getSchemeName())) {
+            return sslSocketFactory.createSocket(sock, targetHost.getHostName(), targetAddress.getPort(), true);
         } else {
             return sock;
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aabcf754/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
index 7a5cebd..cb6700a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
@@ -34,6 +34,7 @@ import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.SocketConfig;
+import org.apache.hc.core5.http.impl.DefaultAddressResolver;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.Http1StreamListener;
 import org.apache.hc.core5.http.impl.HttpProcessors;
@@ -176,7 +177,8 @@ public class RequesterBootstrap {
                 socketConfig != null ? socketConfig : SocketConfig.DEFAULT,
                 connectFactory != null ? connectFactory : new DefaultBHttpClientConnectionFactory(
                         H1Config.DEFAULT, CharCodingConfig.DEFAULT),
-                sslSocketFactory);
+                sslSocketFactory,
+                DefaultAddressResolver.INSTANCE);
     }
 
 }