commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r179411 - in /jakarta/commons/proper/httpclient/trunk/src: java/org/apache/commons/httpclient/HttpParser.java test/org/apache/commons/httpclient/TestHttpParser.java
Date Wed, 01 Jun 2005 20:04:59 GMT
Author: olegk
Date: Wed Jun  1 13:04:58 2005
New Revision: 179411

URL: http://svn.apache.org/viewcvs?rev=179411&view=rev
Log:
PR #35050 (ProtocolException thrown on slightly broken headers)

Contributed by Oleg Kalnichevski
Reviewed by Michael Becke

Modified:
    jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpParser.java
    jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpParser.java

Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpParser.java?rev=179411&r1=179410&r2=179411&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpParser.java
(original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpParser.java
Wed Jun  1 13:04:58 2005
@@ -163,7 +163,7 @@
         StringBuffer value = null;
         for (; ;) {
             String line = HttpParser.readLine(is, charset);
-            if ((line == null) || (line.length() < 1)) {
+            if ((line == null) || (line.trim().length() < 1)) {
                 break;
             }
 

Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpParser.java?rev=179411&r1=179410&r2=179411&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpParser.java
(original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestHttpParser.java
Wed Jun  1 13:04:58 2005
@@ -76,4 +76,50 @@
         assertEquals("stuff", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
         assertEquals(null, HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
     }
+
+    public void testReadWellFormedHttpHeaders() throws Exception {
+        InputStream instream = new ByteArrayInputStream(
+            "a: a\r\nb: b\r\n\r\nwhatever".getBytes(HTTP_ELEMENT_CHARSET));
+        Header[] headers = HttpParser.parseHeaders(instream, HTTP_ELEMENT_CHARSET);
+        assertNotNull(headers);
+        assertEquals(2, headers.length);
+        assertEquals("a", headers[0].getName());
+        assertEquals("a", headers[0].getValue());
+        assertEquals("b", headers[1].getName());
+        assertEquals("b", headers[1].getValue());
+    }
+    
+    public void testReadMalformedHttpHeaders() throws Exception {
+        InputStream instream = new ByteArrayInputStream(
+            "a: a\r\nb b\r\n\r\nwhatever".getBytes(HTTP_ELEMENT_CHARSET));
+        try {
+            Header[] headers = HttpParser.parseHeaders(instream, HTTP_ELEMENT_CHARSET);
+            fail("HttpException should have been thrown");
+        } catch (HttpException expected) {
+        }
+    }
+    
+    public void testHeadersTerminatorLeniency1() throws Exception {
+        InputStream instream = new ByteArrayInputStream(
+            "a: a\r\nb: b\r\n\r\r\nwhatever".getBytes(HTTP_ELEMENT_CHARSET));
+        Header[] headers = HttpParser.parseHeaders(instream, HTTP_ELEMENT_CHARSET);
+        assertNotNull(headers);
+        assertEquals(2, headers.length);
+        assertEquals("a", headers[0].getName());
+        assertEquals("a", headers[0].getValue());
+        assertEquals("b", headers[1].getName());
+        assertEquals("b", headers[1].getValue());
+    }
+    
+    public void testHeadersTerminatorLeniency2() throws Exception {
+        InputStream instream = new ByteArrayInputStream(
+            "a: a\r\nb: b\r\n    \r\nwhatever".getBytes(HTTP_ELEMENT_CHARSET));
+        Header[] headers = HttpParser.parseHeaders(instream, HTTP_ELEMENT_CHARSET);
+        assertNotNull(headers);
+        assertEquals(2, headers.length);
+        assertEquals("a", headers[0].getName());
+        assertEquals("a", headers[0].getValue());
+        assertEquals("b", headers[1].getName());
+        assertEquals("b", headers[1].getValue());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message