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 2022/11/02 09:12:25 UTC

[httpcomponents-core] branch master updated: HTTPCORE-727: Protocol handlers fail to update input metrics when receive input data from a TLS encrypted I/O session

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 5ace3062a HTTPCORE-727: Protocol handlers fail to update input metrics when receive input data from a TLS encrypted I/O session
5ace3062a is described below

commit 5ace3062a54a3d0fc5e7b1074eb759a3c9e951a8
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Oct 31 21:19:43 2022 +0100

    HTTPCORE-727: Protocol handlers fail to update input metrics when receive input data from a TLS encrypted I/O session
---
 .../apache/hc/core5/http2/impl/nio/FrameInputBuffer.java |  5 ++++-
 .../hc/core5/http2/impl/nio/TestFrameInOutBuffers.java   | 16 ++++++++++++++++
 .../core5/http/impl/nio/AbstractHttp1StreamDuplexer.java |  2 ++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/FrameInputBuffer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/FrameInputBuffer.java
index 0c263a586..c0557aece 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/FrameInputBuffer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/FrameInputBuffer.java
@@ -115,13 +115,16 @@ public final class FrameInputBuffer {
                     buffer.clear();
                 }
                 final int remaining = buffer.remaining();
-                if (remaining >= src.remaining()) {
+                final int n = src.remaining();
+                if (remaining >= n) {
                     buffer.put(src);
+                    metrics.incrementBytesTransferred(n);
                 } else {
                     final int limit = src.limit();
                     src.limit(remaining);
                     buffer.put(src);
                     src.limit(limit);
+                    metrics.incrementBytesTransferred(remaining);
                 }
                 buffer.flip();
             }
diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestFrameInOutBuffers.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestFrameInOutBuffers.java
index f1500f19e..dc1662f3c 100644
--- a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestFrameInOutBuffers.java
+++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestFrameInOutBuffers.java
@@ -77,6 +77,22 @@ public class TestFrameInOutBuffers {
 
         Assertions.assertEquals(1, inBuffer.getMetrics().getFramesTransferred());
         Assertions.assertEquals(bytes.length, inBuffer.getMetrics().getBytesTransferred());
+
+        final RawFrame frame3 = inBuffer.read(ByteBuffer.wrap(bytes), readableChannel);
+        Assertions.assertEquals(FrameType.DATA.getValue(), frame3.getType());
+        Assertions.assertEquals(0, frame3.getFlags());
+        Assertions.assertEquals(1L, frame3.getStreamId());
+        final ByteBuffer payload3 = frame3.getPayloadContent();
+        Assertions.assertNotNull(payload3);
+        Assertions.assertEquals(5, payload3.remaining());
+        Assertions.assertEquals(1, payload3.get());
+        Assertions.assertEquals(2, payload3.get());
+        Assertions.assertEquals(3, payload3.get());
+        Assertions.assertEquals(4, payload3.get());
+        Assertions.assertEquals(5, payload3.get());
+
+        Assertions.assertEquals(2, inBuffer.getMetrics().getFramesTransferred());
+        Assertions.assertEquals(bytes.length * 2, inBuffer.getMetrics().getBytesTransferred());
     }
 
     @Test
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
index 21c6d1b00..aec812e7a 100644
--- 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
@@ -262,7 +262,9 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
 
     public final void onInput(final ByteBuffer src) throws HttpException, IOException {
         if (src != null) {
+            final int n = src.remaining();
             inbuf.put(src);
+            inTransportMetrics.incrementBytesTransferred(n);
         }
 
         if (connState.compareTo(ConnectionState.GRACEFUL_SHUTDOWN) >= 0 && inbuf.hasData() && inputIdle()) {