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 2021/10/17 11:02:29 UTC

[httpcomponents-core] branch master updated (0be5f8c -> 1b9b305)

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


    omit 0be5f8c  The required Java verion is 8.
    omit 53c3900  Refactor duplicate patterns with new methods in ContentType: (#306)
    omit e05e0c7  Updated release notes for HttpCore 5.2-alpha2 release
     new 13713eb  Refactor duplicate patterns with new methods in ContentType: (#306)
     new 1b9b305  Updated release notes for HttpCore 5.2-alpha2 release

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (0be5f8c)
            \
             N -- N -- N   refs/heads/master (1b9b305)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 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:

[httpcomponents-core] 01/02: Refactor duplicate patterns with new methods in ContentType: (#306)

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

commit 13713eb5cd3f98f5ebbcb050f51e614b5c5aff6a
Author: Gary Gregory <ga...@users.noreply.github.com>
AuthorDate: Sat Oct 16 10:36:43 2021 -0400

    Refactor duplicate patterns with new methods in ContentType: (#306)
    
    getCharset(ContentType, Charset) and getCharset(Charset).
    
    Co-authored-by: Gary Gregory <gg...@rocketsoftware.com>
---
 .../apache/hc/core5/benchmark/BenchmarkWorker.java |  2 +-
 .../testing/classic/ClassicIntegrationTest.java    | 10 ++------
 .../hc/core5/testing/nio/H2IntegrationTest.java    | 15 +++--------
 .../hc/core5/testing/nio/Http1IntegrationTest.java | 15 +++--------
 .../java/org/apache/hc/core5/http/ContentType.java | 29 +++++++++++++++++++---
 .../hc/core5/http/io/entity/EntityUtils.java       |  3 +--
 .../hc/core5/http/io/entity/StringEntity.java      |  5 +---
 .../entity/AbstractCharAsyncEntityConsumer.java    |  2 +-
 .../entity/AbstractCharAsyncEntityProducer.java    |  5 +---
 .../http/nio/entity/BasicAsyncEntityProducer.java  |  5 +---
 .../org/apache/hc/core5/http/TestContentType.java  | 12 +++++++++
 11 files changed, 51 insertions(+), 52 deletions(-)

diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
index 8fb3fea..46814cc 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
@@ -205,7 +205,7 @@ class BenchmarkWorker implements ResourceHolder {
                     if (config.getVerbosity() >= 6) {
                         if (entityDetails.getContentType() != null) {
                             final ContentType contentType = ContentType.parseLenient(entityDetails.getContentType());
-                            charset = contentType.getCharset();
+                            charset = ContentType.getCharset(contentType, null);
                         }
                     }
                 } else {
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java
index 0d3a978..1427fc8 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java
@@ -580,10 +580,7 @@ public class ClassicIntegrationTest {
             if (entity != null) {
                 final String line = EntityUtils.toString(entity);
                 final ContentType contentType = ContentType.parse(entity.getContentType());
-                Charset charset = contentType.getCharset();
-                if (charset == null) {
-                    charset = StandardCharsets.ISO_8859_1;
-                }
+                final Charset charset = ContentType.getCharset(contentType, StandardCharsets.ISO_8859_1);
                 response.setEntity(new RepeatingEntity(line, charset, n, n % 2 == 0));
             }
         });
@@ -605,10 +602,7 @@ public class ClassicIntegrationTest {
                     Assert.assertNotNull(entity);
                     final InputStream inStream = entity.getContent();
                     final ContentType contentType = ContentType.parse(entity.getContentType());
-                    Charset charset = contentType.getCharset();
-                    if (charset == null) {
-                        charset = StandardCharsets.ISO_8859_1;
-                    }
+                    final Charset charset = ContentType.getCharset(contentType, StandardCharsets.ISO_8859_1);
                     Assert.assertNotNull(inStream);
                     final BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, charset));
 
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java
index 5985436..cb761b3 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2IntegrationTest.java
@@ -349,10 +349,7 @@ public class H2IntegrationTest extends InternalH2ServerTestBase {
                     @Override
                     protected String consumeData(
                             final ContentType contentType, final InputStream inputStream) throws IOException {
-                        Charset charset = contentType != null ? contentType.getCharset() : null;
-                        if (charset == null) {
-                            charset = StandardCharsets.US_ASCII;
-                        }
+                        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
 
                         final StringBuilder buffer = new StringBuilder();
                         try {
@@ -400,10 +397,7 @@ public class H2IntegrationTest extends InternalH2ServerTestBase {
 
                     @Override
                     protected void produceData(final ContentType contentType, final OutputStream outputStream) throws IOException {
-                        Charset charset = contentType.getCharset();
-                        if (charset == null) {
-                            charset = StandardCharsets.US_ASCII;
-                        }
+                        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
                         try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset))) {
                             for (int i = 0; i < 500; i++) {
                                 if (i % 100 == 0) {
@@ -458,10 +452,7 @@ public class H2IntegrationTest extends InternalH2ServerTestBase {
                 }
                 final Header h1 = request.getFirstHeader(HttpHeaders.CONTENT_TYPE);
                 final ContentType contentType = h1 != null ? ContentType.parse(h1.getValue()) : null;
-                Charset charset = contentType != null ? contentType.getCharset() : null;
-                if (charset == null) {
-                    charset = StandardCharsets.US_ASCII;
-                }
+                final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
                 response.setCode(HttpStatus.SC_OK);
                 response.setHeader(h1);
                 try (final BufferedReader reader = new BufferedReader(new InputStreamReader(requestStream, charset));
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index 9640a06..3a05ffb 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -1065,10 +1065,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
                     @Override
                     protected String consumeData(
                             final ContentType contentType, final InputStream inputStream) throws IOException {
-                        Charset charset = contentType != null ? contentType.getCharset() : null;
-                        if (charset == null) {
-                            charset = StandardCharsets.US_ASCII;
-                        }
+                        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
 
                         final StringBuilder buffer = new StringBuilder();
                         try {
@@ -1116,10 +1113,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
 
                     @Override
                     protected void produceData(final ContentType contentType, final OutputStream outputStream) throws IOException {
-                        Charset charset = contentType.getCharset();
-                        if (charset == null) {
-                            charset = StandardCharsets.US_ASCII;
-                        }
+                        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
                         try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset))) {
                             for (int i = 0; i < 500; i++) {
                                 if (i % 100 == 0) {
@@ -1174,10 +1168,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
                 }
                 final Header h1 = request.getFirstHeader(HttpHeaders.CONTENT_TYPE);
                 final ContentType contentType = h1 != null ? ContentType.parse(h1.getValue()) : null;
-                Charset charset = contentType != null ? contentType.getCharset() : null;
-                if (charset == null) {
-                    charset = StandardCharsets.US_ASCII;
-                }
+                final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
                 response.setCode(HttpStatus.SC_OK);
                 response.setHeader(h1);
                 try (final BufferedReader reader = new BufferedReader(new InputStreamReader(requestStream, charset));
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java b/httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java
index 490a743..bfcbcb4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java
@@ -249,6 +249,17 @@ public final class ContentType implements Serializable {
     }
 
     /**
+     * Gets this Charset if it's non-null, otherwise, return the given {@code defaultCharset}.
+     *
+     * @param defaultCharset A default Charset.
+     * @return this Charset if it's non-null, or the given {@code defaultCharset}.
+     * @since 5.2
+     */
+    public Charset getCharset(final Charset defaultCharset) {
+        return this.charset != null ? this.charset : defaultCharset;
+    }
+
+    /**
      * @since 4.3
      */
     public String getParameter(final String name) {
@@ -384,8 +395,7 @@ public final class ContentType implements Serializable {
      * Parses textual representation of {@code Content-Type} value.
      *
      * @param s text
-     * @return content type
-     * {@code Content-Type} value.
+     * @return content type {@code Content-Type} value or null.
      * @throws UnsupportedCharsetException Thrown when the named charset is not available in
      * this instance of the Java virtual machine
      */
@@ -397,8 +407,7 @@ public final class ContentType implements Serializable {
      * Parses textual representation of {@code Content-Type} value ignoring invalid charsets.
      *
      * @param s text
-     * @return content type
-     * {@code Content-Type} value.
+     * @return content type {@code Content-Type} value or null.
      * @throws UnsupportedCharsetException Thrown when the named charset is not available in
      * this instance of the Java virtual machine
      */
@@ -437,6 +446,18 @@ public final class ContentType implements Serializable {
     }
 
     /**
+     * Gets a ContentType's Charset if neither are null, otherwise, return the given {@code defaultCharset}.
+     *
+     * @param contentType the ContentType to test and query.
+     * @param defaultCharset a default Charset.
+     * @return the ContentType's Charset if neither are null, otherwise, return the given {@code defaultCharset}.
+     * @since 5.2
+     */
+    public static Charset getCharset(final ContentType contentType, final Charset defaultCharset) {
+        return contentType != null ? contentType.getCharset(defaultCharset) : defaultCharset;
+    }
+
+    /**
      * Creates a new instance with this MIME type and the given Charset.
      *
      * @param charset charset
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
index 8c185cf..37c6f0d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
@@ -400,8 +400,7 @@ public final class EntityUtils {
         if (!ContentType.APPLICATION_FORM_URLENCODED.isSameMimeType(contentType)) {
             return Collections.emptyList();
         }
-        final Charset charset = contentType.getCharset() != null ? contentType.getCharset()
-                        : DEFAULT_CHARSET;
+        final Charset charset = contentType.getCharset(DEFAULT_CHARSET);
         final CharArrayBuffer buf;
         try (final InputStream inStream = entity.getContent()) {
             if (inStream == null) {
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/StringEntity.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/StringEntity.java
index 8df9532..4dd22b5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/StringEntity.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/StringEntity.java
@@ -62,10 +62,7 @@ public class StringEntity extends AbstractHttpEntity {
             final String string, final ContentType contentType, final String contentEncoding, final boolean chunked) {
         super(contentType, contentEncoding, chunked);
         Args.notNull(string, "Source string");
-        Charset charset = contentType != null ? contentType.getCharset() : null;
-        if (charset == null) {
-            charset = StandardCharsets.ISO_8859_1;
-        }
+        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.ISO_8859_1);
         this.content = string.getBytes(charset);
     }
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
index 34bf15c..c8ed00a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
@@ -79,7 +79,7 @@ public abstract class AbstractCharAsyncEntityConsumer<T> extends AbstractCharDat
         this.resultCallback = resultCallback;
         try {
             final ContentType contentType = entityDetails != null ? ContentType.parse(entityDetails.getContentType()) : null;
-            setCharset(contentType != null ? contentType.getCharset() : null);
+            setCharset(ContentType.getCharset(contentType, null));
             streamStart(contentType);
         } catch (final UnsupportedCharsetException ex) {
             throw new UnsupportedEncodingException(ex.getMessage());
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java
index abbb26d..38a93ed 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java
@@ -70,10 +70,7 @@ public abstract class AbstractCharAsyncEntityProducer implements AsyncEntityProd
         this.fragmentSizeHint = fragmentSizeHint >= 0 ? fragmentSizeHint : 0;
         this.bytebuf = ByteBuffer.allocate(bufferSize);
         this.contentType = contentType;
-        Charset charset = contentType != null ? contentType.getCharset() : null;
-        if (charset == null) {
-            charset = StandardCharsets.US_ASCII;
-        }
+        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
         this.charsetEncoder = charset.newEncoder();
         this.state = State.ACTIVE;
     }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
index f3183b2..9bb55c2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
@@ -73,10 +73,7 @@ public class BasicAsyncEntityProducer implements AsyncEntityProducer {
     public BasicAsyncEntityProducer(final CharSequence content, final ContentType contentType, final boolean chunked) {
         Args.notNull(content, "Content");
         this.contentType = contentType;
-        Charset charset = contentType != null ? contentType.getCharset() : null;
-        if (charset == null) {
-            charset = StandardCharsets.US_ASCII;
-        }
+        final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
         this.bytebuf = charset.encode(CharBuffer.wrap(content));
         this.length = this.bytebuf.remaining();
         this.chunked = chunked;
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java b/httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java
index fea9427..9d4c25b 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/TestContentType.java
@@ -116,6 +116,18 @@ public class TestContentType {
     }
 
     @Test
+    public void testParseDefaultCharset() throws Exception {
+        final ContentType contentType = ContentType.parse("text/plain; charset=\" \"");
+        Assert.assertEquals("text/plain", contentType.getMimeType());
+        Assert.assertNull(contentType.getCharset());
+        Assert.assertEquals(StandardCharsets.US_ASCII, contentType.getCharset(StandardCharsets.US_ASCII));
+        Assert.assertNull(contentType.getCharset(null));
+        //
+        Assert.assertNull(ContentType.getCharset(contentType, null));
+        Assert.assertEquals(StandardCharsets.US_ASCII, ContentType.getCharset(contentType, StandardCharsets.US_ASCII));
+    }
+
+    @Test
     public void testParseEmptyValue() throws Exception {
         Assert.assertNull(ContentType.parse(null));
         Assert.assertNull(ContentType.parse(""));

[httpcomponents-core] 02/02: Updated release notes for HttpCore 5.2-alpha2 release

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

commit 1b9b3053e8f186dd33c1abce9229412aa4cbf5bd
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Oct 16 16:27:16 2021 +0200

    Updated release notes for HttpCore 5.2-alpha2 release
---
 RELEASE_NOTES.txt | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 2267026..5367873 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,13 +1,16 @@
-Release 5.2 ALPHA1
+Release 5.2 ALPHA2
 ------------------
 
-This is the first ALPHA release in the 5.2 release series that upgrades minimal JRE
-level to version 1.8 (8u251 is required) and includes several protocol level and
-API improvements. It also includes all bug fixes from the 5.1 branch.
+This is the second ALPHA release in the 5.2 release series that fixes a regression
+in the TLS layer introduced by the previous ALPHA and adds a number of incremental
+improvements.
+
+Please note that 5.2 upgrades minimal JRE level to version 8 (8u251 is required).
+
 
 Notable changes and features included in the 5.2 series:
 
-* Upgrade to Java 1.8.
+* Upgrade to Java 8.
 
 * Improved support for TLS upgrade and HTTP protocol upgrade (async).
 
@@ -19,6 +22,36 @@ Notable changes and features included in the 5.2 series:
 Change Log
 -------------------
 
+* Add PathEntityProducer, an NIO entity provider (#302).
+  Contributed by Gary Gregory <garydgregory at gmail.com>
+
+* Add SSLContextBuilder NIO Path versions of IO File APIs and re-implement
+  internals with NIO (#301).
+  Contributed by Gary Gregory <garydgregory at gmail.com>
+
+* Allow setting parameters to null arrays and lists to behave like empty (#300).
+  Contributed by Gary Gregory <garydgregory at gmail.com>
+
+* Bug fix, regression: TLS handshake result callback does not get called
+  in case of a timeout.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* HTTPCLIENT-2174: URUBuilder to return a new empty list instead of unmodifiable
+  Collections#emptyList.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+
+Release 5.2 ALPHA1
+------------------
+
+This is the first ALPHA release in the 5.2 release series that upgrades minimal JRE
+level to version 1.8 (8u251 is required) and includes several protocol level and
+API improvements. It also includes all bug fixes from the 5.1 branch.
+
+
+Change Log
+-------------------
+
 * Improved Travis CI build Performance.
   Contributed by Chen Zhang <340355960 at qq.com>