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 2020/09/27 10:42:18 UTC

[httpcomponents-client] branch master updated (9bc49cc -> 918ac15)

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

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


    from 9bc49cc  Fixed 'JdbcRowSetImpl is internal proprietary API and may be removed in a future release' warning
     new 1a70490  HTTPCLIENT-2103: ManagedHttpClientConnectionFactory provides a fluent builder
     new 1c55aa1  HTTPCLIENT-2106: Added charset parameter for DigestScheme
     new 5000f34  Use decimal numbers for endpoint/execution IDs
     new ee5437c  Upgraded HttpCore dependency to version 5.1-beta1
     new ee26e23  Replaced deprecated TokenParser
     new 0524eed  Replaced deprecated URLEncodedUtils
     new 6395fa7  RFC 3986 conformance: revised and optimized `URIUtils#extractHost`
     new 918ac15  RFC 3986 conformance: corrected handling of path segments by `URIUtils#normalizeSyntax`; optimized path segment operations

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../client5/http/impl/cache/HttpCacheSupport.java  |  4 +-
 .../http/impl/cache/TestCacheKeyGenerator.java     |  6 +-
 .../org/apache/hc/client5/http/fluent/Request.java |  4 +-
 .../client5/http/entity/UrlEncodedFormEntity.java  |  4 +-
 .../client5/http/impl/DefaultRedirectStrategy.java |  6 +-
 .../apache/hc/client5/http/impl/ExecSupport.java   |  2 +-
 .../http/impl/auth/AuthChallengeParser.java        | 10 +--
 .../hc/client5/http/impl/auth/DigestScheme.java    | 28 +++++--
 .../http/impl/auth/DigestSchemeFactory.java        | 17 +++-
 .../hc/client5/http/impl/classic/ProxyClient.java  |  7 +-
 .../http/impl/cookie/LaxExpiresHandler.java        |  8 +-
 .../http/impl/cookie/RFC6265CookieSpec.java        | 19 ++---
 .../io/ManagedHttpClientConnectionFactory.java     | 67 +++++++++++++++
 .../io/PoolingHttpClientConnectionManager.java     |  2 +-
 .../nio/PoolingAsyncClientConnectionManager.java   |  2 +-
 .../client5/http/ssl/DistinguishedNameParser.java  | 25 +++---
 .../org/apache/hc/client5/http/utils/URIUtils.java | 97 +++++++---------------
 .../apache/hc/client5/http/utils/TestURIUtils.java | 28 +++----
 pom.xml                                            |  2 +-
 19 files changed, 200 insertions(+), 138 deletions(-)


[httpcomponents-client] 06/08: Replaced deprecated URLEncodedUtils

Posted by ol...@apache.org.
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-client.git

commit 0524eed4b9272c3e88447f1442db90a85d772b49
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 17:17:44 2020 +0200

    Replaced deprecated URLEncodedUtils
---
 .../src/main/java/org/apache/hc/client5/http/fluent/Request.java      | 4 ++--
 .../java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
index b24927d..492adb7 100644
--- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
+++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
@@ -60,7 +60,7 @@ import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
 import org.apache.hc.core5.http.io.entity.FileEntity;
 import org.apache.hc.core5.http.io.entity.InputStreamEntity;
-import org.apache.hc.core5.net.URLEncodedUtils;
+import org.apache.hc.core5.net.WWWFormCodec;
 import org.apache.hc.core5.util.Timeout;
 
 /**
@@ -334,7 +334,7 @@ public class Request {
         }
         final ContentType contentType = charset != null ?
                 ContentType.APPLICATION_FORM_URLENCODED.withCharset(charset) : ContentType.APPLICATION_FORM_URLENCODED;
-        final String s = URLEncodedUtils.format(paramList, contentType.getCharset());
+        final String s = WWWFormCodec.format(paramList, contentType.getCharset());
         return bodyString(s, contentType);
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java
index 9e18a77..156663a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java
@@ -32,7 +32,7 @@ import java.util.List;
 import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.io.entity.StringEntity;
-import org.apache.hc.core5.net.URLEncodedUtils;
+import org.apache.hc.core5.net.WWWFormCodec;
 
 /**
  * An entity composed of a list of url-encoded pairs.
@@ -54,7 +54,7 @@ public class UrlEncodedFormEntity extends StringEntity {
     public UrlEncodedFormEntity(
             final Iterable<? extends NameValuePair> parameters,
             final Charset charset) {
-        super(URLEncodedUtils.format(
+        super(WWWFormCodec.format(
                 parameters,
                 charset != null ? charset : ContentType.APPLICATION_FORM_URLENCODED.getCharset()),
                 charset != null ? ContentType.APPLICATION_FORM_URLENCODED.withCharset(charset) : ContentType.APPLICATION_FORM_URLENCODED);


[httpcomponents-client] 01/08: HTTPCLIENT-2103: ManagedHttpClientConnectionFactory provides a fluent builder

Posted by ol...@apache.org.
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-client.git

commit 1a70490aac71621d4b17f0fe4488df34a782b2e5
Author: Carter Kozak <ck...@apache.org>
AuthorDate: Tue Aug 4 15:06:34 2020 -0400

    HTTPCLIENT-2103: ManagedHttpClientConnectionFactory provides a fluent builder
---
 .../hc/client5/http/impl/classic/ProxyClient.java  |  7 ++-
 .../io/ManagedHttpClientConnectionFactory.java     | 67 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java
index ef7a5ea..fa01137 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java
@@ -104,7 +104,12 @@ public class ProxyClient {
             final CharCodingConfig charCodingConfig,
             final RequestConfig requestConfig) {
         super();
-        this.connFactory = connFactory != null ? connFactory : new ManagedHttpClientConnectionFactory(h1Config, charCodingConfig, null, null);
+        this.connFactory = connFactory != null
+                ? connFactory
+                : ManagedHttpClientConnectionFactory.builder()
+                .http1Config(h1Config)
+                .charCodingConfig(charCodingConfig)
+                .build();
         this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
         this.httpProcessor = new DefaultHttpProcessor(
                 new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
index 63ae378..cce30ca 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
@@ -139,4 +139,71 @@ public class ManagedHttpClientConnectionFactory implements HttpConnectionFactory
         return conn;
     }
 
+    /**
+     * Create a new {@link Builder}.
+     *
+     * @since 5.1
+     */
+    public static Builder builder()  {
+        return new Builder();
+    }
+
+    /**
+     * Builder for {@link ManagedHttpClientConnectionFactory}.
+     *
+     * @since 5.1
+     */
+    public static final class Builder {
+
+        private Http1Config http1Config;
+        private CharCodingConfig charCodingConfig;
+        private ContentLengthStrategy incomingContentLengthStrategy;
+        private ContentLengthStrategy outgoingContentLengthStrategy;
+        private HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory;
+        private HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory;
+
+        private Builder() {}
+
+        public Builder http1Config(final Http1Config http1Config) {
+            this.http1Config = http1Config;
+            return this;
+        }
+
+        public Builder charCodingConfig(final CharCodingConfig charCodingConfig) {
+            this.charCodingConfig = charCodingConfig;
+            return this;
+        }
+
+        public Builder incomingContentLengthStrategy(final ContentLengthStrategy incomingContentLengthStrategy) {
+            this.incomingContentLengthStrategy = incomingContentLengthStrategy;
+            return this;
+        }
+
+        public Builder outgoingContentLengthStrategy(final ContentLengthStrategy outgoingContentLengthStrategy) {
+            this.outgoingContentLengthStrategy = outgoingContentLengthStrategy;
+            return this;
+        }
+
+        public Builder requestWriterFactory(
+                final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory) {
+            this.requestWriterFactory = requestWriterFactory;
+            return this;
+        }
+
+        public Builder responseParserFactory(
+                final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
+            this.responseParserFactory = responseParserFactory;
+            return this;
+        }
+
+        public ManagedHttpClientConnectionFactory build() {
+            return new ManagedHttpClientConnectionFactory(
+                    http1Config,
+                    charCodingConfig,
+                    requestWriterFactory,
+                    responseParserFactory,
+                    incomingContentLengthStrategy,
+                    outgoingContentLengthStrategy);
+        }
+    }
 }


[httpcomponents-client] 04/08: Upgraded HttpCore dependency to version 5.1-beta1

Posted by ol...@apache.org.
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-client.git

commit ee5437c1f1467474e3f232ff25355feba73496ec
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 16:58:52 2020 +0200

    Upgraded HttpCore dependency to version 5.1-beta1
---
 .../apache/hc/client5/http/utils/TestURIUtils.java | 22 +++++++++++-----------
 pom.xml                                            |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
index e2d0340..3706d55 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
@@ -73,7 +73,7 @@ public class TestURIUtils {
                 URI.create("http://thathost")).toString());
         Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
                 URI.create("http://ThatHost")).toString());
-        Assert.assertEquals("http://That_Host/", URIUtils.rewriteURI(
+        Assert.assertEquals("http://that_host/", URIUtils.rewriteURI(
                 URI.create("http://That_Host")).toString());
         Assert.assertEquals("http://thishost/Fragment_identifier%23Examples",
                 URIUtils.rewriteURI(
@@ -111,8 +111,8 @@ public class TestURIUtils {
         Assert.assertEquals("http://www.example.com/a/", URIUtils.resolve(this.baseURI, "http://www.example.com/a%2f").toString());
         Assert.assertEquals("http://www.example.com/?q=%26", URIUtils.resolve(this.baseURI, "http://www.example.com/?q=%26").toString());
         Assert.assertEquals("http://www.example.com/%23?q=%26", URIUtils.resolve(this.baseURI, "http://www.example.com/%23?q=%26").toString());
-        Assert.assertEquals("http://www.example.com/blah-(%20-blah-%20&%20-blah-%20)-blah/",
-                URIUtils.resolve(this.baseURI, "http://www.example.com/blah-%28%20-blah-%20%26%20-blah-%20%29-blah/").toString());
+        Assert.assertEquals("http://www.example.com/blah-%28%20-blah-%20%26%20-blah-%20%29-blah/",
+                URIUtils.resolve(this.baseURI, "http://www.example.com/blah-%28%20-blah-%20&%20-blah-%20)-blah/").toString());
     }
 
     @Test
@@ -122,21 +122,21 @@ public class TestURIUtils {
         Assert.assertEquals("http://a/b/c/g", URIUtils.resolve(this.baseURI, "./g").toString());
         Assert.assertEquals("http://a/b/c/g/", URIUtils.resolve(this.baseURI, "g/").toString());
         Assert.assertEquals("http://a/g", URIUtils.resolve(this.baseURI, "/g").toString());
-        Assert.assertEquals("http://g", URIUtils.resolve(this.baseURI, "//g").toString());
+        Assert.assertEquals("http://g/", URIUtils.resolve(this.baseURI, "//g").toString());
         Assert.assertEquals("http://a/b/c/d;p?y", URIUtils.resolve(this.baseURI, "?y").toString());
         Assert.assertEquals("http://a/b/c/d;p?y#f", URIUtils.resolve(this.baseURI, "?y#f")
                 .toString());
         Assert.assertEquals("http://a/b/c/g?y", URIUtils.resolve(this.baseURI, "g?y").toString());
-        Assert.assertEquals("http://a/b/c/d;p?q#s", URIUtils.resolve(this.baseURI, "#s")
+        Assert.assertEquals("http://a/b/c/d%3Bp?q#s", URIUtils.resolve(this.baseURI, "#s")
                 .toString());
         Assert.assertEquals("http://a/b/c/g#s", URIUtils.resolve(this.baseURI, "g#s").toString());
         Assert.assertEquals("http://a/b/c/g?y#s", URIUtils.resolve(this.baseURI, "g?y#s")
                 .toString());
-        Assert.assertEquals("http://a/b/c/;x", URIUtils.resolve(this.baseURI, ";x").toString());
-        Assert.assertEquals("http://a/b/c/g;x", URIUtils.resolve(this.baseURI, "g;x").toString());
-        Assert.assertEquals("http://a/b/c/g;x?y#s", URIUtils.resolve(this.baseURI, "g;x?y#s")
+        Assert.assertEquals("http://a/b/c/%3Bx", URIUtils.resolve(this.baseURI, ";x").toString());
+        Assert.assertEquals("http://a/b/c/g%3Bx", URIUtils.resolve(this.baseURI, "g;x").toString());
+        Assert.assertEquals("http://a/b/c/g%3Bx?y#s", URIUtils.resolve(this.baseURI, "g;x?y#s")
                 .toString());
-        Assert.assertEquals("http://a/b/c/d;p?q", URIUtils.resolve(this.baseURI, "").toString());
+        Assert.assertEquals("http://a/b/c/d%3Bp?q", URIUtils.resolve(this.baseURI, "").toString());
         Assert.assertEquals("http://a/b/c/", URIUtils.resolve(this.baseURI, ".").toString());
         Assert.assertEquals("http://a/b/c/", URIUtils.resolve(this.baseURI, "./").toString());
         Assert.assertEquals("http://a/b/", URIUtils.resolve(this.baseURI, "..").toString());
@@ -158,7 +158,7 @@ public class TestURIUtils {
         Assert.assertEquals("http://a/b/c/g/", URIUtils.resolve(this.baseURI, "./g/.").toString());
         Assert.assertEquals("http://a/b/c/g/h", URIUtils.resolve(this.baseURI, "g/./h").toString());
         Assert.assertEquals("http://a/b/c/h", URIUtils.resolve(this.baseURI, "g/../h").toString());
-        Assert.assertEquals("http://a/b/c/g;x=1/y", URIUtils.resolve(this.baseURI, "g;x=1/./y")
+        Assert.assertEquals("http://a/b/c/g%3Bx%3D1/y", URIUtils.resolve(this.baseURI, "g;x=1/./y")
                 .toString());
         Assert.assertEquals("http://a/b/c/y", URIUtils.resolve(this.baseURI, "g;x=1/../y")
                 .toString());
@@ -183,7 +183,7 @@ public class TestURIUtils {
         Assert.assertEquals("example://a/b/c/%7Bfoo%7D", URIUtils.resolve(this.baseURI, "eXAMPLE://a/./b/../b/%63/%7bfoo%7d").toString());
         Assert.assertEquals("file://localhost/etc/fstab", URIUtils.resolve(this.baseURI, "file://localhost/etc/fstab").toString());
         Assert.assertEquals("file:///etc/fstab", URIUtils.resolve(this.baseURI, "file:///etc/fstab").toString());
-        Assert.assertEquals("file://localhost/c:/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file://localhost/c:/WINDOWS/clock.avi").toString());
+        Assert.assertEquals("file://localhost/c%3A/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file://localhost/c:/WINDOWS/clock.avi").toString());
         Assert.assertEquals("file:///c:/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file:///c:/WINDOWS/clock.avi").toString());
         Assert.assertEquals("file://hostname/path/to/the%20file.txt", URIUtils.resolve(this.baseURI, "file://hostname/path/to/the%20file.txt").toString());
         Assert.assertEquals("file:///c:/path/to/the%20file.txt", URIUtils.resolve(this.baseURI, "file:///c:/path/to/the%20file.txt").toString());
diff --git a/pom.xml b/pom.xml
index 4928533..c626912 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,7 @@
   <properties>
     <maven.compiler.source>1.7</maven.compiler.source>
     <maven.compiler.target>1.7</maven.compiler.target>
-    <httpcore.version>5.0.2</httpcore.version>
+    <httpcore.version>5.1-beta1</httpcore.version>
     <log4j.version>2.9.1</log4j.version>
     <commons-codec.version>1.13</commons-codec.version>
     <conscrypt.version>2.2.1</conscrypt.version>


[httpcomponents-client] 08/08: RFC 3986 conformance: corrected handling of path segments by `URIUtils#normalizeSyntax`; optimized path segment operations

Posted by ol...@apache.org.
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-client.git

commit 918ac1535f37c47a2230f14b6404d411ee7df91e
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Sep 19 12:56:23 2020 +0200

    RFC 3986 conformance: corrected handling of path segments by `URIUtils#normalizeSyntax`; optimized path segment operations
---
 .../client5/http/impl/cache/HttpCacheSupport.java  |  4 +--
 .../http/impl/cache/TestCacheKeyGenerator.java     |  6 ++--
 .../client5/http/impl/DefaultRedirectStrategy.java |  6 ++--
 .../org/apache/hc/client5/http/utils/URIUtils.java | 40 +++++++++++-----------
 .../apache/hc/client5/http/utils/TestURIUtils.java |  2 +-
 5 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
index 664434c..1233062 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
@@ -115,8 +115,8 @@ public final class HttpCacheSupport {
             }
         }
         builder.setFragment(null);
-        if (builder.getPath() == null) {
-            builder.setPath("/");
+        if (builder.isPathEmpty()) {
+            builder.setPathSegments("");
         }
         return builder.build();
     }
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheKeyGenerator.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheKeyGenerator.java
index ef409c2..c6c9ba0 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheKeyGenerator.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheKeyGenerator.java
@@ -382,7 +382,7 @@ public class TestCacheKeyGenerator {
     public void testIntermidateEncodedDotDotSegementsAreEquivalent() {
         final HttpHost host = new HttpHost("foo.example.com");
         final HttpRequest req1 = new BasicHttpRequest("GET", "/home.html");
-        final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith%2F../home.html");
+        final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/../home.html");
         Assert.assertEquals(extractor.generateKey(host, req1), extractor.generateKey(host, req2));
     }
 
@@ -406,7 +406,7 @@ public class TestCacheKeyGenerator {
     public void testEquivalentExtraPathEncodingsAreEquivalent() {
         final HttpHost host = new HttpHost("foo.example.com");
         final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
-        final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith%2Fhome.html");
+        final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home.html");
         Assert.assertEquals(extractor.generateKey(host, req1), extractor.generateKey(host, req2));
     }
 
@@ -414,7 +414,7 @@ public class TestCacheKeyGenerator {
     public void testEquivalentExtraPathEncodingsWithPercentAreEquivalent() {
         final HttpHost host = new HttpHost("foo.example.com");
         final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home%20folder.html");
-        final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith%2Fhome%20folder.html");
+        final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home%20folder.html");
         Assert.assertEquals(extractor.generateKey(host, req1), extractor.generateKey(host, req2));
     }
 }
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultRedirectStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultRedirectStrategy.java
index ed82bfa..8899766 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultRedirectStrategy.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultRedirectStrategy.java
@@ -45,7 +45,6 @@ import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.net.URIBuilder;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.TextUtils;
 
 /**
  * Default implementation of {@link RedirectStrategy}.
@@ -119,9 +118,8 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
             if (host != null) {
                 b.setHost(host.toLowerCase(Locale.ROOT));
             }
-            final String path = b.getPath();
-            if (TextUtils.isEmpty(path)) {
-                b.setPath("/");
+            if (b.isPathEmpty()) {
+                b.setPathSegments("");
             }
             return b.build();
         } catch (final URISyntaxException ex) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
index 0f8814f..3fe9cf0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
@@ -133,8 +133,8 @@ public class URIUtils {
         if (uribuilder.getUserInfo() != null) {
             uribuilder.setUserInfo(null);
         }
-        if (TextUtils.isEmpty(uribuilder.getPath())) {
-            uribuilder.setPath("/");
+        if (uribuilder.isPathEmpty()) {
+            uribuilder.setPathSegments("");
         }
         if (uribuilder.getHost() != null) {
             uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ROOT));
@@ -203,30 +203,30 @@ public class URIUtils {
         }
         Args.check(uri.isAbsolute(), "Base URI must be absolute");
         final URIBuilder builder = new URIBuilder(uri);
-        final String path = builder.getPath();
-        if (path != null && !path.equals("/")) {
-            final String[] inputSegments = path.split("/");
+        if (!builder.isPathEmpty()) {
+            final List<String> inputSegments = builder.getPathSegments();
             final Stack<String> outputSegments = new Stack<>();
             for (final String inputSegment : inputSegments) {
-                if ((inputSegment.isEmpty()) || (".".equals(inputSegment))) {
-                    // Do nothing
-                } else if ("..".equals(inputSegment)) {
-                    if (!outputSegments.isEmpty()) {
-                        outputSegments.pop();
+                if (!inputSegment.isEmpty() && !".".equals(inputSegment)) {
+                    if ("..".equals(inputSegment)) {
+                        if (!outputSegments.isEmpty()) {
+                            outputSegments.pop();
+                        }
+                    } else {
+                        outputSegments.push(inputSegment);
                     }
-                } else {
-                    outputSegments.push(inputSegment);
                 }
             }
-            final StringBuilder outputBuffer = new StringBuilder();
-            for (final String outputSegment : outputSegments) {
-                outputBuffer.append('/').append(outputSegment);
-            }
-            if (path.lastIndexOf('/') == path.length() - 1) {
-                // path.endsWith("/") || path.equals("")
-                outputBuffer.append('/');
+            if (!inputSegments.isEmpty()) {
+                final String lastSegment = inputSegments.get(inputSegments.size() - 1);
+                if (lastSegment.isEmpty()) {
+                    outputSegments.push("");
+                }
             }
-            builder.setPath(outputBuffer.toString());
+            builder.setPathSegments(outputSegments);
+        }
+        if (builder.isPathEmpty()) {
+            builder.setPathSegments("");
         }
         if (builder.getScheme() != null) {
             builder.setScheme(builder.getScheme().toLowerCase(Locale.ROOT));
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
index 11632a4..d70cfb6 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
@@ -108,7 +108,7 @@ public class TestURIUtils {
         Assert.assertEquals("example://a/b/c/%7Bfoo%7D", URIUtils.resolve(this.baseURI, "eXAMPLE://a/./b/../b/%63/%7bfoo%7d").toString());
         Assert.assertEquals("http://www.example.com/%3C", URIUtils.resolve(this.baseURI, "http://www.example.com/%3c").toString());
         Assert.assertEquals("http://www.example.com/", URIUtils.resolve(this.baseURI, "HTTP://www.EXAMPLE.com/").toString());
-        Assert.assertEquals("http://www.example.com/a/", URIUtils.resolve(this.baseURI, "http://www.example.com/a%2f").toString());
+        Assert.assertEquals("http://www.example.com/a%2F", URIUtils.resolve(this.baseURI, "http://www.example.com/a%2f").toString());
         Assert.assertEquals("http://www.example.com/?q=%26", URIUtils.resolve(this.baseURI, "http://www.example.com/?q=%26").toString());
         Assert.assertEquals("http://www.example.com/%23?q=%26", URIUtils.resolve(this.baseURI, "http://www.example.com/%23?q=%26").toString());
         Assert.assertEquals("http://www.example.com/blah-%28%20-blah-%20%26%20-blah-%20%29-blah/",


[httpcomponents-client] 07/08: RFC 3986 conformance: revised and optimized `URIUtils#extractHost`

Posted by ol...@apache.org.
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-client.git

commit 6395fa7c79b62f99d0c114702dc0bcc8a5ef97ad
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Sep 17 11:21:09 2020 +0200

    RFC 3986 conformance: revised and optimized `URIUtils#extractHost`
---
 .../org/apache/hc/client5/http/utils/URIUtils.java | 57 ++++------------------
 .../apache/hc/client5/http/utils/TestURIUtils.java |  4 +-
 2 files changed, 11 insertions(+), 50 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
index bf53275..0f8814f 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
@@ -250,56 +250,17 @@ public class URIUtils {
         if (uri == null) {
             return null;
         }
-        HttpHost target = null;
-        if (uri.isAbsolute()) {
-            int port = uri.getPort(); // may be overridden later
-            String host = uri.getHost();
-            if (host == null) { // normal parse failed; let's do it ourselves
-                // authority does not seem to care about the valid character-set for host names
-                host = uri.getAuthority();
-                if (host != null) {
-                    // Strip off any leading user credentials
-                    final int at = host.indexOf('@');
-                    if (at >= 0) {
-                        if (host.length() > at+1 ) {
-                            host = host.substring(at+1);
-                        } else {
-                            host = null; // @ on its own
-                        }
-                    }
-                    // Extract the port suffix, if present
-                    if (host != null) {
-                        final int colon = host.indexOf(':');
-                        if (colon >= 0) {
-                            final int pos = colon + 1;
-                            int len = 0;
-                            for (int i = pos; i < host.length(); i++) {
-                                if (Character.isDigit(host.charAt(i))) {
-                                    len++;
-                                } else {
-                                    break;
-                                }
-                            }
-                            if (len > 0) {
-                                try {
-                                    port = Integer.parseInt(host.substring(pos, pos + len));
-                                } catch (final NumberFormatException ex) {
-                                }
-                            }
-                            host = host.substring(0, colon);
-                        }
-                    }
-                }
-            }
-            final String scheme = uri.getScheme();
-            if (!TextUtils.isBlank(host)) {
-                try {
-                    target = new HttpHost(scheme, host, port);
-                } catch (final IllegalArgumentException ignore) {
-                }
+        final URIBuilder uriBuilder = new URIBuilder(uri);
+        final String scheme = uriBuilder.getScheme();
+        final String host = uriBuilder.getHost();
+        final int port = uriBuilder.getPort();
+        if (!TextUtils.isBlank(host)) {
+            try {
+                return new HttpHost(scheme, host, port);
+            } catch (final IllegalArgumentException ignore) {
             }
         }
-        return target;
+        return null;
     }
 
     /**
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
index 3706d55..11632a4 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
@@ -230,9 +230,9 @@ public class TestURIUtils {
 
         Assert.assertEquals(new HttpHost("localhost",8080),
                 URIUtils.extractHost(new URI("http://localhost:8080/;sessionid=stuff/abcd")));
-        Assert.assertEquals(new HttpHost("localhost",8080),
+        Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://localhost:8080;sessionid=stuff/abcd")));
-        Assert.assertEquals(new HttpHost("localhost",-1),
+        Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://localhost:;sessionid=stuff/abcd")));
         Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://:80/robots.txt")));


[httpcomponents-client] 03/08: Use decimal numbers for endpoint/execution IDs

Posted by ol...@apache.org.
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-client.git

commit 5000f3469062f74db3afaed9f5b5bedade107049
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Tue Aug 18 12:16:46 2020 +0200

    Use decimal numbers for endpoint/execution IDs
    
    This closes #249
---
 .../src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java      | 2 +-
 .../hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java     | 2 +-
 .../hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
index c9e42ba..4d7c5f6 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
@@ -45,7 +45,7 @@ public final class ExecSupport {
     }
 
     public static String getNextExchangeId() {
-        return String.format("ex-%08X", COUNT.incrementAndGet());
+        return String.format("ex-%010d", COUNT.incrementAndGet());
     }
 
 }
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 d4799e6..94b9592 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
@@ -529,7 +529,7 @@ public class PoolingHttpClientConnectionManager
         InternalConnectionEndpoint(
                 final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry) {
             this.poolEntryRef = new AtomicReference<>(poolEntry);
-            this.id = String.format("ep-%08X", COUNT.getAndIncrement());
+            this.id = String.format("ep-%010d", COUNT.getAndIncrement());
         }
 
         @Override
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 a6c6daf..b187cd1 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
@@ -492,7 +492,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
 
         InternalConnectionEndpoint(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
             this.poolEntryRef = new AtomicReference<>(poolEntry);
-            this.id = String.format("ep-%08X", COUNT.getAndIncrement());
+            this.id = String.format("ep-%010d", COUNT.getAndIncrement());
         }
 
         @Override


[httpcomponents-client] 05/08: Replaced deprecated TokenParser

Posted by ol...@apache.org.
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-client.git

commit ee26e23b31011b641b1bbc646fe38d42d0e72d00
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 17:14:11 2020 +0200

    Replaced deprecated TokenParser
---
 .../http/impl/auth/AuthChallengeParser.java        | 10 ++++-----
 .../http/impl/cookie/LaxExpiresHandler.java        |  8 +++----
 .../http/impl/cookie/RFC6265CookieSpec.java        | 19 ++++++++--------
 .../client5/http/ssl/DistinguishedNameParser.java  | 25 +++++++++++-----------
 4 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
index 8fd57fe..3a7d1a7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
@@ -37,8 +37,8 @@ import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
 import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Authentication challenge parser.
@@ -49,7 +49,7 @@ public class AuthChallengeParser {
 
     public static final AuthChallengeParser INSTANCE = new AuthChallengeParser();
 
-    private final TokenParser tokenParser = TokenParser.INSTANCE;
+    private final Tokenizer tokenParser = Tokenizer.INSTANCE;
 
     private final static char BLANK            = ' ';
     private final static char COMMA_CHAR       = ',';
@@ -57,9 +57,9 @@ public class AuthChallengeParser {
 
     // IMPORTANT!
     // These private static variables must be treated as immutable and never exposed outside this class
-    private static final BitSet TERMINATORS = TokenParser.INIT_BITSET(BLANK, EQUAL_CHAR, COMMA_CHAR);
-    private static final BitSet DELIMITER = TokenParser.INIT_BITSET(COMMA_CHAR);
-    private static final BitSet SPACE = TokenParser.INIT_BITSET(BLANK);
+    private static final BitSet TERMINATORS = Tokenizer.INIT_BITSET(BLANK, EQUAL_CHAR, COMMA_CHAR);
+    private static final BitSet DELIMITER = Tokenizer.INIT_BITSET(COMMA_CHAR);
+    private static final BitSet SPACE = Tokenizer.INIT_BITSET(BLANK);
 
     static class ChallengeInt {
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
index c48be4f..357f8a8 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
@@ -41,9 +41,9 @@ import org.apache.hc.client5.http.cookie.MalformedCookieException;
 import org.apache.hc.client5.http.cookie.SetCookie;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.message.ParserCursor;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Cookie {@code expires} attribute handler conformant to the more relaxed interpretation
@@ -111,7 +111,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         if (TextUtils.isBlank(value)) {
             return;
         }
-        final ParserCursor cursor = new ParserCursor(0, value.length());
+        final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, value.length());
         final StringBuilder content = new StringBuilder();
 
         int second = 0, minute = 0, hour = 0, day = 0, month = 0, year = 0;
@@ -188,7 +188,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         cookie.setExpiryDate(c.getTime());
     }
 
-    private void skipDelims(final CharSequence buf, final ParserCursor cursor) {
+    private void skipDelims(final CharSequence buf, final Tokenizer.Cursor cursor) {
         int pos = cursor.getPos();
         final int indexFrom = cursor.getPos();
         final int indexTo = cursor.getUpperBound();
@@ -203,7 +203,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         cursor.updatePos(pos);
     }
 
-    private void copyContent(final CharSequence buf, final ParserCursor cursor, final StringBuilder dst) {
+    private void copyContent(final CharSequence buf, final Tokenizer.Cursor cursor, final StringBuilder dst) {
         int pos = cursor.getPos();
         final int indexFrom = cursor.getPos();
         final int indexTo = cursor.getUpperBound();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
index 97668f0..c815bc0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
@@ -50,10 +50,9 @@ import org.apache.hc.core5.http.FormattedHeader;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.BufferedHeader;
-import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Cookie management functions shared by RFC C6265 compliant specification.
@@ -71,14 +70,14 @@ public class RFC6265CookieSpec implements CookieSpec {
 
     // IMPORTANT!
     // These private static variables must be treated as immutable and never exposed outside this class
-    private static final BitSet TOKEN_DELIMS = TokenParser.INIT_BITSET(EQUAL_CHAR, PARAM_DELIMITER);
-    private static final BitSet VALUE_DELIMS = TokenParser.INIT_BITSET(PARAM_DELIMITER);
-    private static final BitSet SPECIAL_CHARS = TokenParser.INIT_BITSET(' ',
+    private static final BitSet TOKEN_DELIMS = Tokenizer.INIT_BITSET(EQUAL_CHAR, PARAM_DELIMITER);
+    private static final BitSet VALUE_DELIMS = Tokenizer.INIT_BITSET(PARAM_DELIMITER);
+    private static final BitSet SPECIAL_CHARS = Tokenizer.INIT_BITSET(' ',
             DQUOTE_CHAR, COMMA_CHAR, PARAM_DELIMITER, ESCAPE_CHAR);
 
     private final CookieAttributeHandler[] attribHandlers;
     private final Map<String, CookieAttributeHandler> attribHandlerMap;
-    private final TokenParser tokenParser;
+    private final Tokenizer tokenParser;
 
     protected RFC6265CookieSpec(final CommonCookieAttributeHandler... handlers) {
         super();
@@ -87,7 +86,7 @@ public class RFC6265CookieSpec implements CookieSpec {
         for (final CommonCookieAttributeHandler handler: handlers) {
             this.attribHandlerMap.put(handler.getAttributeName().toLowerCase(Locale.ROOT), handler);
         }
-        this.tokenParser = TokenParser.INSTANCE;
+        this.tokenParser = Tokenizer.INSTANCE;
     }
 
     static String getDefaultPath(final CookieOrigin origin) {
@@ -115,10 +114,10 @@ public class RFC6265CookieSpec implements CookieSpec {
             throw new MalformedCookieException("Unrecognized cookie header: '" + header + "'");
         }
         final CharArrayBuffer buffer;
-        final ParserCursor cursor;
+        final Tokenizer.Cursor cursor;
         if (header instanceof FormattedHeader) {
             buffer = ((FormattedHeader) header).getBuffer();
-            cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
+            cursor = new Tokenizer.Cursor(((FormattedHeader) header).getValuePos(), buffer.length());
         } else {
             final String s = header.getValue();
             if (s == null) {
@@ -126,7 +125,7 @@ public class RFC6265CookieSpec implements CookieSpec {
             }
             buffer = new CharArrayBuffer(s.length());
             buffer.append(s);
-            cursor = new ParserCursor(0, buffer.length());
+            cursor = new Tokenizer.Cursor(0, buffer.length());
         }
         final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
         if (name.isEmpty()) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
index 0053c1c..4e3dc8a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
@@ -33,32 +33,31 @@ import java.util.List;
 
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
-import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.Tokenizer;
 
 final class DistinguishedNameParser {
 
     public final static DistinguishedNameParser INSTANCE = new DistinguishedNameParser();
 
-    private static final BitSet EQUAL_OR_COMMA_OR_PLUS      = TokenParser.INIT_BITSET('=', ',', '+');
-    private static final BitSet COMMA_OR_PLUS               = TokenParser.INIT_BITSET(',', '+');
+    private static final BitSet EQUAL_OR_COMMA_OR_PLUS      = Tokenizer.INIT_BITSET('=', ',', '+');
+    private static final BitSet COMMA_OR_PLUS               = Tokenizer.INIT_BITSET(',', '+');
 
-    private final TokenParser tokenParser;
+    private final Tokenizer tokenParser;
 
     DistinguishedNameParser() {
         this.tokenParser = new InternalTokenParser();
     }
 
-    private String parseToken(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
+    private String parseToken(final CharArrayBuffer buf, final Tokenizer.Cursor cursor, final BitSet delimiters) {
         return tokenParser.parseToken(buf, cursor, delimiters);
     }
 
-    private String parseValue(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
+    private String parseValue(final CharArrayBuffer buf, final Tokenizer.Cursor cursor, final BitSet delimiters) {
         return tokenParser.parseValue(buf, cursor, delimiters);
     }
 
-    private NameValuePair parseParameter(final CharArrayBuffer buf, final ParserCursor cursor) {
+    private NameValuePair parseParameter(final CharArrayBuffer buf, final Tokenizer.Cursor cursor) {
         final String name = parseToken(buf, cursor, EQUAL_OR_COMMA_OR_PLUS);
         if (cursor.atEnd()) {
             return new BasicNameValuePair(name, null);
@@ -75,7 +74,7 @@ final class DistinguishedNameParser {
         return new BasicNameValuePair(name, value);
     }
 
-    List<NameValuePair> parse(final CharArrayBuffer buf, final ParserCursor cursor) {
+    List<NameValuePair> parse(final CharArrayBuffer buf, final Tokenizer.Cursor cursor) {
         final List<NameValuePair> params = new ArrayList<>();
         tokenParser.skipWhiteSpace(buf, cursor);
         while (!cursor.atEnd()) {
@@ -91,16 +90,16 @@ final class DistinguishedNameParser {
         }
         final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
         buffer.append(s);
-        final ParserCursor cursor = new ParserCursor(0, s.length());
+        final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, s.length());
         return parse(buffer, cursor);
     }
 
-    static class InternalTokenParser extends TokenParser {
+    static class InternalTokenParser extends Tokenizer {
 
         @Override
         public void copyUnquotedContent(
                 final CharSequence buf,
-                final ParserCursor cursor,
+                final Tokenizer.Cursor cursor,
                 final BitSet delimiters,
                 final StringBuilder dst) {
             int pos = cursor.getPos();
@@ -114,7 +113,7 @@ final class DistinguishedNameParser {
                     escaped = false;
                 } else {
                     if ((delimiters != null && delimiters.get(current))
-                            || TokenParser.isWhitespace(current) || current == '\"') {
+                            || Tokenizer.isWhitespace(current) || current == '\"') {
                         break;
                     } else if (current == '\\') {
                         escaped = true;


[httpcomponents-client] 02/08: HTTPCLIENT-2106: Added charset parameter for DigestScheme

Posted by ol...@apache.org.
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-client.git

commit 1c55aa1548f04af9d84bfd4df023e6ecd63f3378
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Aug 10 15:28:44 2020 +0200

    HTTPCLIENT-2106: Added charset parameter for DigestScheme
---
 .../hc/client5/http/impl/auth/DigestScheme.java    | 28 ++++++++++++++++++----
 .../http/impl/auth/DigestSchemeFactory.java        | 17 ++++++++++++-
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
index 7353e6f..9aec188 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
@@ -27,6 +27,8 @@
 package org.apache.hc.client5.http.impl.auth;
 
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
@@ -46,13 +48,13 @@ import java.util.StringTokenizer;
 
 import org.apache.hc.client5.http.auth.AuthChallenge;
 import org.apache.hc.client5.http.auth.AuthScheme;
-import org.apache.hc.client5.http.auth.StandardAuthScheme;
 import org.apache.hc.client5.http.auth.AuthScope;
 import org.apache.hc.client5.http.auth.AuthenticationException;
-import org.apache.hc.client5.http.utils.ByteArrayBuilder;
 import org.apache.hc.client5.http.auth.Credentials;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
 import org.apache.hc.client5.http.auth.MalformedChallengeException;
+import org.apache.hc.client5.http.auth.StandardAuthScheme;
+import org.apache.hc.client5.http.utils.ByteArrayBuilder;
 import org.apache.hc.core5.annotation.Internal;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.HttpEntity;
@@ -103,6 +105,7 @@ public class DigestScheme implements AuthScheme, Serializable {
     private static final int QOP_AUTH_INT = 1;
     private static final int QOP_AUTH = 2;
 
+    private transient Charset defaultCharset;
     private final Map<String, String> paramMap;
     private boolean complete;
     private transient ByteArrayBuilder buffer;
@@ -117,6 +120,11 @@ public class DigestScheme implements AuthScheme, Serializable {
     private char[] password;
 
     public DigestScheme() {
+        this(StandardCharsets.ISO_8859_1);
+    }
+
+    public DigestScheme(final Charset charset) {
+        this.defaultCharset = charset != null ? charset : StandardCharsets.ISO_8859_1;
         this.paramMap = new HashMap<>();
         this.complete = false;
     }
@@ -263,11 +271,11 @@ public class DigestScheme implements AuthScheme, Serializable {
         }
 
         final String charsetName = this.paramMap.get("charset");
-        Charset charset;
+        final Charset charset;
         try {
-            charset = charsetName != null ? Charset.forName(charsetName) : StandardCharsets.ISO_8859_1;
+            charset = charsetName != null ? Charset.forName(charsetName) : defaultCharset;
         } catch (final UnsupportedCharsetException ex) {
-            charset = StandardCharsets.ISO_8859_1;
+            throw new AuthenticationException("Unsupported charset: " + charsetName);
         }
 
         String digAlg = algorithm;
@@ -470,6 +478,16 @@ public class DigestScheme implements AuthScheme, Serializable {
         return tmp;
     }
 
+    private void writeObject(final ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        out.writeUTF(defaultCharset.name());
+    }
+
+    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        this.defaultCharset = Charset.forName(in.readUTF());
+    }
+
     @Override
     public String toString() {
         return getName() + this.paramMap;
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestSchemeFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestSchemeFactory.java
index 26e7898..2e3c5ad 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestSchemeFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestSchemeFactory.java
@@ -27,6 +27,8 @@
 
 package org.apache.hc.client5.http.impl.auth;
 
+import java.nio.charset.Charset;
+
 import org.apache.hc.client5.http.auth.AuthScheme;
 import org.apache.hc.client5.http.auth.AuthSchemeFactory;
 import org.apache.hc.core5.annotation.Contract;
@@ -47,9 +49,22 @@ public class DigestSchemeFactory implements AuthSchemeFactory {
      */
     public static final DigestSchemeFactory INSTANCE = new DigestSchemeFactory();
 
+    private final Charset charset;
+
+    /**
+     * @since 5.1
+     */
+    public DigestSchemeFactory(final Charset charset) {
+        this.charset = charset;
+    }
+
+    public DigestSchemeFactory() {
+        this(null);
+    }
+
     @Override
     public AuthScheme create(final HttpContext context) {
-        return new DigestScheme();
+        return new DigestScheme(charset);
     }
 
 }