Author: jfclere
Date: Sat Apr 27 14:42:09 2013
New Revision: 1476592

URL: http://svn.apache.org/r1476592
Log:
commit accepted patch for Chunked encoding improvements.

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1476592&r1=1476591&r2=1476592&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Sat Apr 27 14:42:09 2013
@@ -53,11 +53,6 @@ PATCHES PROPOSED TO BACKPORT:
   +1: kkolinko, schultz
   -1:
 
-* Chunked encoding improvements
-  http://people.apache.org/~markt/patches/2012-10-19-chunked-encoding-tc6.patch
-  +1: markt, kkolinko, jfclere
-  -1:
-
 * Improve method cache handling in SecurityUtil class.
   Add caching for Comet methods and simplify cache lookup code.
   It is backport of r728776 (BZ 46304) and r1429360

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java?rev=1476592&r1=1476591&r2=1476592&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
 Sat Apr 27 14:42:09 2013
@@ -148,7 +148,7 @@ public class ChunkedInputFilter implemen
 
         if(needCRLFParse) {
             needCRLFParse = false;
-            parseCRLF();
+            parseCRLF(false);
         }
 
         if (remaining <= 0) {
@@ -186,7 +186,7 @@ public class ChunkedInputFilter implemen
                 //so we defer it to the next call BZ 11117
                 needCRLFParse = true;
             } else {
-                parseCRLF(); //parse the CRLF immediately
+                parseCRLF(false); //parse the CRLF immediately
             }
         }
 
@@ -303,8 +303,8 @@ public class ChunkedInputFilter implemen
                     return false;
             }
 
-            if (buf[pos] == Constants.CR) {
-            } else if (buf[pos] == Constants.LF) {
+            if (buf[pos] == Constants.CR || buf[pos] == Constants.LF) {
+                parseCRLF(false);
                 eol = true;
             } else if (buf[pos] == Constants.SEMI_COLON) {
                 trailer = true;
@@ -322,7 +322,10 @@ public class ChunkedInputFilter implemen
                 }
             }
 
-            pos++;
+            // Parsing the CRLF increments pos
+            if (!eol) {
+                pos++;
+            }
 
         }
 
@@ -343,9 +346,22 @@ public class ChunkedInputFilter implemen
 
     /**
      * Parse CRLF at end of chunk.
+     * @deprecated  Use {@link #parseCRLF(boolean)}
      */
-    protected boolean parseCRLF()
-        throws IOException {
+    @Deprecated
+    protected boolean parseCRLF() throws IOException {
+        parseCRLF(false);
+        return true;
+    }
+
+    /**
+     * Parse CRLF at end of chunk.
+     *
+     * @param   tolerant    Should tolerant parsing (LF and CRLF) be used? This
+     *                      is recommended (RFC2616, section 19.3) for message
+     *                      headers.
+     */
+    protected void parseCRLF(boolean tolerant) throws IOException {
 
         boolean eol = false;
         boolean crfound = false;
@@ -361,7 +377,9 @@ public class ChunkedInputFilter implemen
                 if (crfound) throw new IOException("Invalid CRLF, two CR 
characters encountered.");
                 crfound = true;
             } else if (buf[pos] == Constants.LF) {
-                if (!crfound) throw new IOException("Invalid CRLF, no CR 
character encountered.");
+                if (!tolerant && !crfound) {
+                    throw new IOException("Invalid CRLF, no CR character 
encountered.");
+                }
                 eol = true;
             } else {
                 throw new IOException("Invalid CRLF");
@@ -370,9 +388,6 @@ public class ChunkedInputFilter implemen
             pos++;
 
         }
-
-        return true;
-
     }
 
 
@@ -394,26 +409,19 @@ public class ChunkedInputFilter implemen
         MimeHeaders headers = request.getMimeHeaders();
 
         byte chr = 0;
-        while (true) {
-            // Read new bytes if needed
-            if (pos >= lastValid) {
-                if (readBytes() <0)
-                    throw new EOFException("Unexpected end of stream whilst 
reading trailer headers for chunked request");
-            }
 
-            chr = buf[pos];
-    
-            if ((chr == Constants.CR) || (chr == Constants.LF)) {
-                if (chr == Constants.LF) {
-                    pos++;
-                    return false;
-                }
-            } else {
-                break;
-            }
-    
-            pos++;
+        // Read new bytes if needed
+        if (pos >= lastValid) {
+            if (readBytes() <0)
+                throw new EOFException("Unexpected end of stream whilst 
reading trailer headers for chunked request");
+        }
     
+        chr = buf[pos];
+
+        // CRLF terminates the request
+        if (chr == Constants.CR || chr == Constants.LF) {
+            parseCRLF(false);
+            return false;
         }
     
         // Mark the current buffer position
@@ -493,9 +501,8 @@ public class ChunkedInputFilter implemen
                 }
     
                 chr = buf[pos];
-                if (chr == Constants.CR) {
-                    // Skip
-                } else if (chr == Constants.LF) {
+                if (chr == Constants.CR || chr == Constants.LF) {
+                    parseCRLF(true);
                     eol = true;
                 } else if (chr == Constants.SP) {
                     trailingHeaders.append(chr);
@@ -504,8 +511,9 @@ public class ChunkedInputFilter implemen
                     lastSignificantChar = trailingHeaders.getEnd();
                 }
     
-                pos++;
-    
+                if (!eol) {
+                    pos++;
+                }
             }
     
             // Checking the first character of the new line. If the character



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to