Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CD42D200C8E for ; Wed, 24 May 2017 09:39:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CC391160BB4; Wed, 24 May 2017 07:39:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 01E84160B9C for ; Wed, 24 May 2017 09:39:55 +0200 (CEST) Received: (qmail 39185 invoked by uid 500); 24 May 2017 07:39:55 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 39172 invoked by uid 99); 24 May 2017 07:39:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 May 2017 07:39:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E83ADDFB01; Wed, 24 May 2017 07:39:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ggregory@apache.org To: commits@hc.apache.org Date: Wed, 24 May 2017 07:39:54 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] httpcomponents-client git commit: [HTTPCORE-466] Round out the SslContextBuilder by adding missing APIs. archived-at: Wed, 24 May 2017 07:39:57 -0000 Repository: httpcomponents-client Updated Branches: refs/heads/4.6.x 5ca2eda57 -> aa4817707 [HTTPCORE-466] Round out the SslContextBuilder by adding missing APIs. Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/0b91f9ed Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/0b91f9ed Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/0b91f9ed Branch: refs/heads/4.6.x Commit: 0b91f9ed0221494e6a0541cfb69889a5c62c7c1d Parents: 9aff64d Author: Gary Gregory Authored: Wed May 24 00:38:49 2017 -0700 Committer: Gary Gregory Committed: Wed May 24 00:38:49 2017 -0700 ---------------------------------------------------------------------- RELEASE_NOTES.txt | 3 ++ .../apache/http/client/utils/URIBuilder.java | 23 +++++++++++++++ .../org/apache/http/client/utils/URIUtils.java | 2 +- .../http/client/utils/TestURIBuilder.java | 31 +++++++++++++++++++- 4 files changed, 57 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/0b91f9ed/RELEASE_NOTES.txt ---------------------------------------------------------------------- diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 8b4a804..0ec2acf 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -39,6 +39,9 @@ Change log: * [HTTPCLIENT-1828] HttpDelete, HttpGet, HttpHead do not extend HttpEntityEnclosingRequestBase. Contributed by Saravanakumar Selvaraj and Gary Gregory +* [HTTPCORE-466] Round out the SslContextBuilder by adding missing APIs. + Contributed by Gary Gregory + Release 4.5.3 ------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/0b91f9ed/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java ---------------------------------------------------------------------- diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java b/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java index 91f198c..5d9d897 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java @@ -26,8 +26,10 @@ */ package org.apache.http.client.utils; +import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; +import java.net.UnknownHostException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Iterator; @@ -46,6 +48,15 @@ import org.apache.http.util.TextUtils; */ public class URIBuilder { + /** + * Creates a new builder for the host {@link InetAddress#getLocalHost()}. + * + * @since 4.6 + */ + public static URIBuilder localhost() throws UnknownHostException { + return new URIBuilder().setHost(InetAddress.getLocalHost()); + } + private String scheme; private String encodedSchemeSpecificPart; private String encodedAuthority; @@ -248,6 +259,18 @@ public class URIBuilder { /** * Sets URI host. + * + * @since 4.6 + */ + public URIBuilder setHost(final InetAddress host) { + this.host = host.getHostAddress(); + this.encodedSchemeSpecificPart = null; + this.encodedAuthority = null; + return this; + } + + /** + * Sets URI host. */ public URIBuilder setHost(final String host) { this.host = host; http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/0b91f9ed/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java ---------------------------------------------------------------------- diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java index 02f8c1a..2ab4b58 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java @@ -141,7 +141,7 @@ public class URIUtils { uribuilder.setPort(target.getPort()); } else { uribuilder.setScheme(null); - uribuilder.setHost(null); + uribuilder.setHost((String) null); uribuilder.setPort(-1); } if (dropFragment) { http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/0b91f9ed/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java ---------------------------------------------------------------------- diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java index 8bca89e..5095d39 100644 --- a/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java +++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java @@ -26,6 +26,7 @@ */ package org.apache.http.client.utils; +import java.net.InetAddress; import java.net.URI; import java.net.URLEncoder; import java.nio.charset.Charset; @@ -51,7 +52,7 @@ public class TestURIBuilder { @Test public void testMutationToRelativeUri() throws Exception { final URI uri = new URI("http://stuff@localhost:80/stuff?param=stuff#fragment"); - final URIBuilder uribuilder = new URIBuilder(uri).setHost(null); + final URIBuilder uribuilder = new URIBuilder(uri).setHost((String) null); final URI result = uribuilder.build(); Assert.assertEquals(new URI("http:///stuff?param=stuff#fragment"), result); } @@ -211,6 +212,34 @@ public class TestURIBuilder { } @Test + public void testLocalhost() throws Exception { + // Check that the URI generated by URI builder agrees with that generated by using URI directly + final String scheme="https"; + final InetAddress host=InetAddress.getLocalHost(); + final String specials="/abcd!$&*()_-+.,=:;'~@[]?<>|#^%\"{}\\\u00a3`\u00ac\u00a6xyz"; // N.B. excludes space + final URI uri = new URI(scheme, specials, host.getHostAddress(), 80, specials, specials, specials); + + final URI bld = URIBuilder.localhost() + .setScheme(scheme) + .setUserInfo(specials) + .setPath(specials) + .setCustomQuery(specials) + .setFragment(specials) + .build(); + + Assert.assertEquals(uri.getHost(), bld.getHost()); + + Assert.assertEquals(uri.getUserInfo(), bld.getUserInfo()); + + Assert.assertEquals(uri.getPath(), bld.getPath()); + + Assert.assertEquals(uri.getQuery(), bld.getQuery()); + + Assert.assertEquals(uri.getFragment(), bld.getFragment()); + + } + + @Test public void testAgainstURIEncoded() throws Exception { // Check that the encoded URI generated by URI builder agrees with that generated by using URI directly final String scheme="https";