Port fix from TC5. As per RFC2616, requests with multiple content-length headers...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 3 Mar 2007 15:56:14 +0000 (15:56 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 3 Mar 2007 15:56:14 +0000 (15:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@514176 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/Request.java
java/org/apache/tomcat/util/http/MimeHeaders.java

index 2156275..63c1e3d 100644 (file)
@@ -294,7 +294,7 @@ public final class Request {
     public long getContentLengthLong() {
         if( contentLength > -1 ) return contentLength;
 
-        MessageBytes clB = headers.getValue("content-length");
+        MessageBytes clB = headers.getUniqueValue("content-length");
         contentLength = (clB == null || clB.isNull()) ? -1 : clB.getLong();
 
         return contentLength;
index 1bb3362..4dd9147 100644 (file)
@@ -293,6 +293,25 @@ public class MimeHeaders {
         return null;
     }
 
+    /**
+     * Finds and returns a unique header field with the given name. If no such
+     * field exists, null is returned. If the specified header field is not
+     * unique then an {@link IllegalArgumentException} is thrown. 
+     */
+    public MessageBytes getUniqueValue(String name) {
+        MessageBytes result = null;
+        for (int i = 0; i < count; i++) {
+            if (headers[i].getName().equalsIgnoreCase(name)) {
+                if (result == null) {
+                    result = headers[i].getValue();
+                } else {
+                    throw new IllegalArgumentException();
+                }
+            }
+        }
+        return result;
+    }
+
     // bad shortcut - it'll convert to string ( too early probably,
     // encoding is guessed very late )
     public String getHeader(String name) {