hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [49/50] [abbrv] httpcomponents-core git commit: Fixed delineation of 200 status message in response to CONNECT method
Date Tue, 09 May 2017 19:58:41 GMT
Fixed delineation of 200 status message in response to CONNECT method

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1794176 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/e1c42bf3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/e1c42bf3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/e1c42bf3

Branch: refs/heads/trunk
Commit: e1c42bf35bb9e6291d212648876c926002525211
Parents: 96b9e84
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Sat May 6 19:33:22 2017 +0000
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Sat May 6 19:33:22 2017 +0000

----------------------------------------------------------------------
 .../http/impl/DefaultConnectionReuseStrategy.java | 16 ++++------------
 .../http/impl/nio/ClientHttp1StreamDuplexer.java  |  9 ++-------
 .../http/impl/nio/ClientHttp1StreamHandler.java   |  4 ++--
 .../hc/core5/http/message/MessageSupport.java     | 18 ++++++++++++++++++
 4 files changed, 26 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
index 8aaa4f5..27c2fe2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
@@ -37,10 +37,10 @@ import org.apache.hc.core5.http.HeaderElements;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
 import org.apache.hc.core5.http.message.BasicTokenIterator;
+import org.apache.hc.core5.http.message.MessageSupport;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.Args;
 
@@ -97,7 +97,9 @@ public class DefaultConnectionReuseStrategy implements ConnectionReuseStrategy
{
                 return false;
             }
         } else {
-            if (canResponseHaveBody(request, response) && response.containsHeaders(HttpHeaders.CONTENT_LENGTH)
!= 1) {
+            final String method = request != null ? request.getMethod() : null;
+            if (MessageSupport.canResponseHaveBody(method, response)
+                    && response.containsHeaders(HttpHeaders.CONTENT_LENGTH) != 1)
{
                 return false;
             }
         }
@@ -134,14 +136,4 @@ public class DefaultConnectionReuseStrategy implements ConnectionReuseStrategy
{
         return ver.greaterEquals(HttpVersion.HTTP_1_1);
     }
 
-    private boolean canResponseHaveBody(final HttpRequest request, final HttpResponse response)
{
-        if (request != null && request.getMethod().equalsIgnoreCase("HEAD")) {
-            return false;
-        }
-        final int status = response.getCode();
-        return status >= HttpStatus.SC_SUCCESS
-            && status != HttpStatus.SC_NO_CONTENT
-            && status != HttpStatus.SC_NOT_MODIFIED;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
index 32100a2..f5a55fc 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
@@ -42,7 +42,6 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.LengthRequiredException;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
@@ -52,6 +51,7 @@ import org.apache.hc.core5.http.impl.ConnectionListener;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.message.MessageSupport;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.apache.hc.core5.http.nio.ContentDecoder;
@@ -268,12 +268,7 @@ public class ClientHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
         if (incoming == null) {
             throw new HttpException("Unexpected response");
         }
-
-        if (incoming.isHeadRequest()) {
-            return null;
-        }
-        final int status = response.getCode();
-        if (status < HttpStatus.SC_SUCCESS || status == HttpStatus.SC_NO_CONTENT || status
== HttpStatus.SC_NOT_MODIFIED) {
+        if (!MessageSupport.canResponseHaveBody(incoming.getRequestMethod(), response)) {
             return null;
         }
         final long len = incomingContentStrategy.determineLength(response);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
index b5eb490..c5394a2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
@@ -125,8 +125,8 @@ class ClientHttp1StreamHandler implements ResourceHolder {
         return requestState == MessageState.COMPLETE && responseState == MessageState.COMPLETE;
     }
 
-    boolean isHeadRequest() {
-        return committedRequest != null && "HEAD".equalsIgnoreCase(committedRequest.getMethod());
+    String getRequestMethod() {
+        return committedRequest != null ? committedRequest.getMethod() : null;
     }
 
     boolean isOutputReady() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
index 2d24b26..91226bd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
@@ -39,6 +39,8 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpMessage;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.MessageHeaders;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
@@ -169,4 +171,20 @@ public class MessageSupport {
         return BasicHeaderValueParser.INSTANCE.parseElements(value, cursor);
     }
 
+    /**
+     * @since  5.0
+     */
+    public static boolean canResponseHaveBody(final String method, final HttpResponse response)
{
+        if ("HEAD".equalsIgnoreCase(method)) {
+            return false;
+        }
+        final int status = response.getCode();
+        if ("CONNECT".equalsIgnoreCase(method) && status == HttpStatus.SC_OK) {
+            return false;
+        }
+        return status >= HttpStatus.SC_SUCCESS
+                && status != HttpStatus.SC_NO_CONTENT
+                && status != HttpStatus.SC_NOT_MODIFIED;
+    }
+
 }


Mime
View raw message