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 13:34:06 UTC

[httpcomponents-core] 01/03: HTTPCORE-727 (follow-up): async HTTP/1.1 protocol handler fails to count bytes transferred while flushing session buffer when writing out a message head or suspending session output.

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 8fabd3dc130a6a3ebb037faf736acd0cb46e0b0e
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Nov 2 12:53:07 2022 +0100

    HTTPCORE-727 (follow-up): async HTTP/1.1 protocol handler fails to count bytes transferred while flushing session buffer when writing out a message head or suspending session output.
---
 .../hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

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 aec812e7a..b60adf2dc 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
@@ -446,7 +446,10 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
             }
             outgoingMessageWriter.reset();
             if (flushMode == FlushMode.IMMEDIATE) {
-                outbuf.flush(ioSession);
+                final int bytesWritten = outbuf.flush(ioSession);
+                if (bytesWritten > 0) {
+                    outTransportMetrics.incrementBytesTransferred(bytesWritten);
+                }
             }
             ioSession.setEvent(EventMask.WRITE);
         } finally {
@@ -479,7 +482,10 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
         ioSession.getLock().lock();
         try {
             if (outbuf.hasData()) {
-                outbuf.flush(ioSession);
+                final int bytesWritten = outbuf.flush(ioSession);
+                if (bytesWritten > 0) {
+                    outTransportMetrics.incrementBytesTransferred(bytesWritten);
+                }
             } else {
                 ioSession.clearEvent(SelectionKey.OP_WRITE);
             }