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 2017/05/09 20:04:04 UTC

[35/35] httpcomponents-core git commit: Fully merged the fix for HTTPCORE-296

Fully merged the fix for HTTPCORE-296

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.1.x@1302143 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/9d0d6115
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/9d0d6115
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/9d0d6115

Branch: refs/heads/4.1.x
Commit: 9d0d6115caf7ade10012df136d8f47bef0711288
Parents: e45e29f
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sun Mar 18 15:48:22 2012 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sun Mar 18 15:48:22 2012 +0000

----------------------------------------------------------------------
 .../impl/nio/DefaultNHttpServerConnection.java  |  2 +-
 .../http/impl/nio/NHttpConnectionBase.java      | 23 -----------------
 .../http/impl/AbstractHttpServerConnection.java |  2 +-
 .../DisallowIdentityContentLengthStrategy.java  |  2 --
 .../impl/entity/LaxContentLengthStrategy.java   | 27 ++++++++++++++++----
 .../entity/StrictContentLengthStrategy.java     | 27 ++++++++++++++++----
 .../protocol/TestHttpServiceAndExecutor.java    |  2 +-
 7 files changed, 47 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
index f180954..43b3056 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
@@ -97,7 +97,7 @@ public class DefaultNHttpServerConnection
 
     @Override
     protected ContentLengthStrategy createIncomingContentStrategy() {
-        return new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy());
+        return new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy(0));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
index a1f6b91..cbc8e83 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
@@ -159,38 +159,15 @@ public class NHttpConnectionBase
         this.remote = this.session.getRemoteAddress();
     }
 
-    /**
-<<<<<<< HEAD
-=======
-     * Binds the connection to a different {@link IOSession}. This may be necessary
-     * when the underlying I/O session gets upgraded with SSL/TLS encryption.
-     *
-     * @since 4.2
-     */
-    protected void bind(final IOSession session) {
-        if (session == null) {
-            throw new IllegalArgumentException("I/O session may not be null");
-        }
-        this.session.setBufferStatus(null);
-        setSession(session);
-    }
-
-    /**
-     * @since 4.2
-     */
     protected ContentLengthStrategy createIncomingContentStrategy() {
         return new LaxContentLengthStrategy();
     }
 
-    /**
-     * @since 4.2
-     */
     protected ContentLengthStrategy createOutgoingContentStrategy() {
         return new StrictContentLengthStrategy();
     }
 
     /**
->>>>>>> 74acee1... HTTPCORE-296: server side connections (both blocking and non-blocking) can now handle entity enclosing requests without Content-Length and Transfer-Encoding headers
      * @since 4.1
      */
     protected HttpTransportMetricsImpl createTransportMetrics() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java b/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
index 322c946..3485095 100644
--- a/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
+++ b/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
@@ -116,7 +116,7 @@ public abstract class AbstractHttpServerConnection implements HttpServerConnecti
      */
     protected EntityDeserializer createEntityDeserializer() {
         return new EntityDeserializer(new DisallowIdentityContentLengthStrategy(
-                new LaxContentLengthStrategy()));
+                new LaxContentLengthStrategy(0)));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java b/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
index 8a5ba49..17d0b0b 100644
--- a/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
+++ b/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
@@ -35,8 +35,6 @@ import org.apache.http.entity.ContentLengthStrategy;
 /**
  * Decorator for  {@link ContentLengthStrategy} implementations that disallows the use of 
  * identity transfer encoding. 
- *
- * @since 4.2
  */
 public class DisallowIdentityContentLengthStrategy implements ContentLengthStrategy {
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java b/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
index 72b0425..45c0438 100644
--- a/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
+++ b/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
@@ -55,8 +55,25 @@ import org.apache.http.protocol.HTTP;
  */
 public class LaxContentLengthStrategy implements ContentLengthStrategy {
 
-    public LaxContentLengthStrategy() {
+    private final int implicitLen;
+    
+    /**
+     * Creates <tt>LaxContentLengthStrategy</tt> instance with the given length used per default
+     * when content length is not explicitly specified in the message.
+     * 
+     * @param implicit implicit content length.
+     */
+    public LaxContentLengthStrategy(int implicitLen) {
         super();
+        this.implicitLen = implicitLen;
+    }
+
+    /**
+     * Creates <tt>LaxContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY} 
+     * is used per default when content length is not explicitly specified in the message.
+     */
+    public LaxContentLengthStrategy() {
+        this(IDENTITY);
     }
 
     public long determineLength(final HttpMessage message) throws HttpException {
@@ -68,7 +85,6 @@ public class LaxContentLengthStrategy implements ContentLengthStrategy {
         boolean strict = params.isParameterTrue(CoreProtocolPNames.STRICT_TRANSFER_ENCODING);
 
         Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
-        Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
         // We use Transfer-Encoding if present and ignore Content-Length.
         // RFC2616, 4.4 item number 3
         if (transferEncodingHeader != null) {
@@ -104,7 +120,9 @@ public class LaxContentLengthStrategy implements ContentLengthStrategy {
                 }
                 return IDENTITY;
             }
-        } else if (contentLengthHeader != null) {
+        }
+        Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
+        if (contentLengthHeader != null) {
             long contentlen = -1;
             Header[] headers = message.getHeaders(HTTP.CONTENT_LEN);
             if (strict && headers.length > 1) {
@@ -127,9 +145,8 @@ public class LaxContentLengthStrategy implements ContentLengthStrategy {
             } else {
                 return IDENTITY;
             }
-        } else {
-            return IDENTITY;
         }
+        return this.implicitLen;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java b/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
index 8575d3d..3054d85 100644
--- a/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
+++ b/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
@@ -47,8 +47,25 @@ import org.apache.http.protocol.HTTP;
  */
 public class StrictContentLengthStrategy implements ContentLengthStrategy {
 
-    public StrictContentLengthStrategy() {
+    private final int implicitLen;
+    
+    /**
+     * Creates <tt>StrictContentLengthStrategy</tt> instance with the given length used per default
+     * when content length is not explicitly specified in the message.
+     * 
+     * @param implicit implicit content length.
+     */
+    public StrictContentLengthStrategy(int implicitLen) {
         super();
+        this.implicitLen = implicitLen;
+    }
+
+    /**
+     * Creates <tt>StrictContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY} 
+     * is used per default when content length is not explicitly specified in the message.
+     */
+    public StrictContentLengthStrategy() {
+        this(IDENTITY);
     }
 
     public long determineLength(final HttpMessage message) throws HttpException {
@@ -59,7 +76,6 @@ public class StrictContentLengthStrategy implements ContentLengthStrategy {
         // it is either missing or has the single value "chunked". So we
         // treat it as a single-valued header here.
         Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
-        Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
         if (transferEncodingHeader != null) {
             String s = transferEncodingHeader.getValue();
             if (HTTP.CHUNK_CODING.equalsIgnoreCase(s)) {
@@ -75,7 +91,9 @@ public class StrictContentLengthStrategy implements ContentLengthStrategy {
                 throw new ProtocolException(
                         "Unsupported transfer encoding: " + s);
             }
-        } else if (contentLengthHeader != null) {
+        }
+        Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
+        if (contentLengthHeader != null) {
             String s = contentLengthHeader.getValue();
             try {
                 long len = Long.parseLong(s);
@@ -86,9 +104,8 @@ public class StrictContentLengthStrategy implements ContentLengthStrategy {
             } catch (NumberFormatException e) {
                 throw new ProtocolException("Invalid content length: " + s);
             }
-        } else {
-            return IDENTITY;
         }
+        return this.implicitLen;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d0d6115/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java b/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java
index 660a10a..15f945d 100644
--- a/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java
+++ b/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java
@@ -851,7 +851,7 @@ public class TestHttpServiceAndExecutor extends TestCase {
                             new RequestExpectContinue() }));
             
             HttpResponse response = this.client.execute(post, host, conn);
-            assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
+            assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         } finally {
             conn.close();
             this.server.shutdown();