Index: httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java --- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java (revision a52a4c5042591c245a8da5441924430e49fd03a5) +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java (date 1665696632332) @@ -106,6 +106,7 @@ } private void expandCapacity(final int capacity) { + System.out.println("Expanding capacity: " + capacity); final ByteBuffer oldBuffer = this.buffer; this.buffer = ByteBuffer.allocate(capacity); oldBuffer.flip(); Index: httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== 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 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java (revision a52a4c5042591c245a8da5441924430e49fd03a5) +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java (date 1665697339445) @@ -160,7 +160,7 @@ } private static final Timeout TIMEOUT = Timeout.ofSeconds(30); - private static final Timeout LONG_TIMEOUT = Timeout.ofSeconds(60); + private static final Timeout LONG_TIMEOUT = Timeout.ofSeconds(600); private Http1TestClient client; @@ -1280,6 +1280,66 @@ } } + @Test + public void testLargeResponseConsumer() throws Exception { + final byte[] asciiBytes = new byte[200]; + for (int i = 0; i < 200; ++i) { + asciiBytes[i] = (byte) ((i % 26) + 'a'); + } + final String largeMessage = Arrays.toString(asciiBytes); + server.register("/", new Supplier() { + + @Override + public AsyncServerExchangeHandler get() { + return new MultiLineResponseHandler(largeMessage, 10000); + } + + }); + final InetSocketAddress serverEndpoint = server.start(); + + client.start(Http1Config.custom().setBufferSize(256).build()); + + final Future connectFuture = client.connect( + "localhost", serverEndpoint.getPort(), TIMEOUT); + final ClientSessionEndpoint streamEndpoint = connectFuture.get(); + + final HttpRequest request1 = new BasicHttpRequest(Method.GET, createRequestURI(serverEndpoint, "/")); + final Future> future1 = streamEndpoint.execute( + new BasicRequestProducer(request1, null), + new BasicResponseConsumer<>(new AbstractClassicEntityConsumer(16, Executors.newSingleThreadExecutor()) { + + @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 StringBuilder buffer = new StringBuilder(); + final byte[] tmp = new byte[16]; + int l; + while ((l = inputStream.read(tmp)) != -1) { + buffer.append(charset.decode(ByteBuffer.wrap(tmp, 0, l))); + } + return buffer.toString(); + } + }), + null); + + final Message result1 = future1.get(LONG_TIMEOUT.getDuration(), LONG_TIMEOUT.getTimeUnit()); + Assert.assertNotNull(result1); + final HttpResponse response1 = result1.getHead(); + Assert.assertNotNull(response1); + Assert.assertEquals(200, response1.getCode()); + final String s1 = result1.getBody(); + Assert.assertNotNull(s1); + final StringTokenizer t1 = new StringTokenizer(s1, "\r\n"); + while (t1.hasMoreTokens()) { + Assert.assertEquals(largeMessage, t1.nextToken()); + } + } + @Test public void testSlowRequestProducer() throws Exception { server.register("*", new Supplier() { Index: httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java --- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java (revision a52a4c5042591c245a8da5441924430e49fd03a5) +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java (date 1665697460376) @@ -637,6 +637,7 @@ if (window <= 0) { ioSession.clearEvent(SelectionKey.OP_READ); } + System.out.println("window: " + window); return window; } }