You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2023/01/13 13:05:39 UTC

[httpcomponents-core] branch master updated: HTTPCORE-733: BasicAsyncEntityProducer sends an extra trailing 0 with UTF-8 encoded content

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


The following commit(s) were added to refs/heads/master by this push:
     new 473fc0a71 HTTPCORE-733: BasicAsyncEntityProducer sends an extra trailing 0 with UTF-8 encoded content
473fc0a71 is described below

commit 473fc0a71ed63ecca29694fac6db396cf9be334b
Author: Oleg Kalnichevski <Ol...@abraxas.ch>
AuthorDate: Fri Jan 13 14:05:16 2023 +0100

    HTTPCORE-733: BasicAsyncEntityProducer sends an extra trailing 0 with UTF-8 encoded content
---
 .../hc/core5/http/nio/entity/BasicAsyncEntityProducer.java |  1 +
 .../http/nio/entity/TestBasicAsyncEntityProducer.java      | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

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 9bb55c240..0a2bb6ded 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
@@ -147,6 +147,7 @@ public class BasicAsyncEntityProducer implements AsyncEntityProducer {
     @Override
     public void releaseResources() {
         bytebuf.clear();
+        bytebuf.limit(length);
     }
 
 }
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestBasicAsyncEntityProducer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestBasicAsyncEntityProducer.java
index d2fa09a17..072e13e42 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestBasicAsyncEntityProducer.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestBasicAsyncEntityProducer.java
@@ -99,4 +99,18 @@ public class TestBasicAsyncEntityProducer {
         }
     }
 
+    @Test
+    public void testTextContentRepeatableUTF() throws Exception {
+        final String content = "<testtag></testtag>";
+        final AsyncEntityProducer producer = new BasicAsyncEntityProducer(content, ContentType.TEXT_XML);
+        for (int i = 0; i < 3; i++) {
+            final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
+            final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
+            producer.produce(streamChannel);
+            Assertions.assertFalse(byteChannel.isOpen());
+            Assertions.assertEquals(content, byteChannel.dump(StandardCharsets.UTF_8));
+            producer.releaseResources();
+        }
+    }
+
 }