hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [29/50] [abbrv] httpcomponents-core git commit: Refactor range validation into new Args util methods.
Date Tue, 09 May 2017 19:58:21 GMT
Refactor range validation into new Args util methods.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792667 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: f29e5fe4f887f122cae3dcdcd34dc4d172abf4e5
Parents: 65b1b58
Author: Gary D. Gregory <ggregory@apache.org>
Authored: Tue Apr 25 22:34:03 2017 +0000
Committer: Gary D. Gregory <ggregory@apache.org>
Committed: Tue Apr 25 22:34:03 2017 +0000

----------------------------------------------------------------------
 .../apache/hc/core5/http2/config/H2Config.java  |  3 +--
 .../hc/core5/http/io/entity/EntityUtils.java    |  6 ++----
 .../java/org/apache/hc/core5/util/Args.java     | 20 +++++++++++---------
 3 files changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f29e5fe4/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
index b7b5e45..ce4821f 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
@@ -165,9 +165,8 @@ public class H2Config {
         }
 
         public Builder setMaxFrameSize(final int maxFrameSize) {
-            Args.checkRange(maxFrameSize, FrameConsts.MIN_FRAME_SIZE, FrameConsts.MAX_FRAME_SIZE,
+            this.maxFrameSize = Args.checkRange(maxFrameSize, FrameConsts.MIN_FRAME_SIZE,
FrameConsts.MAX_FRAME_SIZE,
                     "Invalid max frame size");
-            this.maxFrameSize = maxFrameSize;
             return this;
         }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f29e5fe4/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
index 975befa..546e9cd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
@@ -201,8 +201,7 @@ public final class EntityUtils {
             return null;
         }
         try {
-            Args.checkContentLength(entity);
-            int i = (int)entity.getContentLength();
+            int i = (int) Args.checkContentLength(entity);
             if (i < 0) {
                 i = 4096;
             }
@@ -226,8 +225,7 @@ public final class EntityUtils {
             return null;
         }
         try {
-            Args.checkContentLength(entity);
-            int i = (int) entity.getContentLength();
+            int i = (int) Args.checkContentLength(entity);
             if (i < 0) {
                 i = 4096;
             }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f29e5fe4/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
index 98d8ad8..78fadc4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
@@ -51,27 +51,29 @@ public class Args {
         }
     }
 
-    public static void checkRange(final int value, final int lowInclusive, final int highInclusive,
+    public static long checkContentLength(final EntityDetails entityDetails) {
+        // -1 is a special value
+        // 0 is allowed as well
+        return checkRange(entityDetails.getContentLength(), -1, Integer.MAX_VALUE,
+                "HTTP entity too large to be buffered in memory)");
+    }
+
+    public static int checkRange(final int value, final int lowInclusive, final int highInclusive,
             final String message) {
         if (value < lowInclusive || value > highInclusive) {
             throw new IllegalArgumentException(String.format("%s: %,d is out of range [%,d,
%,d]", message,
                     Integer.valueOf(value), Integer.valueOf(lowInclusive), Integer.valueOf(highInclusive)));
         }
+        return value;
     }
 
-    public static void checkRange(final long value, final long lowInclusive, final long highInclusive,
+    public static long checkRange(final long value, final long lowInclusive, final long highInclusive,
             final String message) {
         if (value < lowInclusive || value > highInclusive) {
             throw new IllegalArgumentException(String.format("%s: %,d is out of range [%,d,
%,d]", message,
                     Long.valueOf(value), Long.valueOf(lowInclusive), Long.valueOf(highInclusive)));
         }
-    }
-
-    public static void checkContentLength(final EntityDetails entityDetails) {
-        // -1 is a special value
-        // 0 is allowed as well
-        checkRange(entityDetails.getContentLength(), -1, Integer.MAX_VALUE,
-                "HTTP entity too large to be buffered in memory)");
+        return value;
     }
 
     public static <T extends CharSequence> T containsNoBlanks(final T argument, final
String name) {


Mime
View raw message