You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2018/08/14 00:07:28 UTC

httpcomponents-core git commit: Access completed state via methods (better for debugging too.)

Repository: httpcomponents-core
Updated Branches:
  refs/heads/4.4.x 6f1cb1226 -> 287ad54fb


Access completed state via methods (better for debugging too.)

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/287ad54f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/287ad54f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/287ad54f

Branch: refs/heads/4.4.x
Commit: 287ad54fbea37e54d0b80501351f3ea9b7431e0f
Parents: 6f1cb12
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 18:07:26 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Aug 13 18:07:26 2018 -0600

----------------------------------------------------------------------
 .../http/impl/nio/codecs/AbstractContentDecoder.java  | 13 +++++++++++++
 .../org/apache/http/impl/nio/codecs/ChunkDecoder.java |  6 +++---
 .../apache/http/impl/nio/codecs/IdentityDecoder.java  |  8 ++++----
 .../http/impl/nio/codecs/LengthDelimitedDecoder.java  | 14 +++++++-------
 4 files changed, 27 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/287ad54f/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentDecoder.java
index 0fcbd2c..ec97452 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentDecoder.java
@@ -91,6 +91,19 @@ public abstract class AbstractContentDecoder implements ContentDecoder {
     }
 
     /**
+     * Sets the completed status of this decoder to true. Normally this is not necessary
+     * (the decoder will automatically complete when the underlying channel
+     * returns EOF). It is useful to mark the decoder as completed if you have
+     * some other means to know all the necessary data has been read and want to
+     * reuse the underlying connection for more messages.
+     *
+     * @since 4.4.11
+     */
+    protected void setCompleted() {
+        this.completed = true;
+    }
+
+    /**
      * Reads from the channel to the destination.
      *
      * @param dst destination.

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/287ad54f/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
index 5bc3291..77e05dd 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
@@ -222,7 +222,7 @@ public class ChunkDecoder extends AbstractContentDecoder {
                 } else {
                     if (!this.buffer.hasData() && this.endOfStream) {
                         this.state = COMPLETED;
-                        this.completed = true;
+                        setCompleted();
                         throw new TruncatedChunkException(
                                         "Truncated chunk (expected size: %,d; actual size: %,d)",
                                         chunkSize, pos);
@@ -247,7 +247,7 @@ public class ChunkDecoder extends AbstractContentDecoder {
                     // Unable to read a footer
                     if (this.endOfStream) {
                         this.state = COMPLETED;
-                        this.completed = true;
+                        setCompleted();
                     }
                     return totalRead;
                 }
@@ -259,7 +259,7 @@ public class ChunkDecoder extends AbstractContentDecoder {
                     parseHeader();
                 } else {
                     this.state = COMPLETED;
-                    this.completed = true;
+                    setCompleted();
                     processFooters();
                 }
                 break;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/287ad54f/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
index fddd480..461263a 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/IdentityDecoder.java
@@ -62,7 +62,7 @@ public class IdentityDecoder extends AbstractContentDecoder
     @Override
     public int read(final ByteBuffer dst) throws IOException {
         Args.notNull(dst, "Byte buffer");
-        if (this.completed) {
+        if (isCompleted()) {
             return -1;
         }
 
@@ -73,7 +73,7 @@ public class IdentityDecoder extends AbstractContentDecoder
             bytesRead = readFromChannel(dst);
         }
         if (bytesRead == -1) {
-            this.completed = true;
+            setCompleted();
         }
         return bytesRead;
     }
@@ -87,7 +87,7 @@ public class IdentityDecoder extends AbstractContentDecoder
         if (dst == null) {
             return 0;
         }
-        if (this.completed) {
+        if (isCompleted()) {
             return 0;
         }
 
@@ -113,7 +113,7 @@ public class IdentityDecoder extends AbstractContentDecoder
             }
         }
         if (bytesRead == -1) {
-            this.completed = true;
+            setCompleted();
         }
         return bytesRead;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/287ad54f/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
index 1493f3d..2df2f45 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
@@ -71,7 +71,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
     @Override
     public int read(final ByteBuffer dst) throws IOException {
         Args.notNull(dst, "Byte buffer");
-        if (this.completed) {
+        if (isCompleted()) {
             return -1;
         }
         final int chunk = (int) Math.min((this.contentLength - this.len), Integer.MAX_VALUE);
@@ -84,7 +84,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
             bytesRead = readFromChannel(dst, chunk);
         }
         if (bytesRead == -1) {
-            this.completed = true;
+            setCompleted();
             if (this.len < this.contentLength) {
                 throw new ConnectionClosedException(
                                 "Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
@@ -93,9 +93,9 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
         }
         this.len += bytesRead;
         if (this.len >= this.contentLength) {
-            this.completed = true;
+            setCompleted();
         }
-        return this.completed && bytesRead == 0 ? -1 : bytesRead;
+        return isCompleted() && bytesRead == 0 ? -1 : bytesRead;
     }
 
     @Override
@@ -107,7 +107,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
         if (dst == null) {
             return 0;
         }
-        if (this.completed) {
+        if (isCompleted()) {
             return -1;
         }
 
@@ -133,7 +133,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
             }
         }
         if (bytesRead == -1) {
-            this.completed = true;
+            setCompleted();
             if (this.len < this.contentLength) {
                 throw new ConnectionClosedException(
                                 "Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
@@ -142,7 +142,7 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
         }
         this.len += bytesRead;
         if (this.len >= this.contentLength) {
-            this.completed = true;
+            setCompleted();
         }
         return bytesRead;
     }