Patch: FYI: fix http Headers oddity

Bryce McKinlay mckinlay@redhat.com
Mon May 16 22:17:00 GMT 2005


Does anyone know why we use the custom "LineInputStream" class instead 
of, say, BufferedReader here? At one point BufferedReader.readLine() was 
buggy and could "read too much" and block before returning a line, but I 
believe we have fixed that. Code re-use would help to avoid bugs like 
this ;-)

Bryce


Tom Tromey wrote:

>I'm checking this in on the trunk, the 4.0 branch, and Classpath.
>
>This fixes a bug that occurs when an http server erroneously uses \n
>as a line terminator rather than \r\n.  This lets us use a certain web
>applet I ran across.
>
>Tom
>
>Index: ChangeLog
>from  Tom Tromey  <tromey@redhat.com>
>	* gnu/java/net/protocol/http/Headers.java (parse): Include final
>	character of line.
>
>Index: gnu/java/net/protocol/http/Headers.java
>===================================================================
>RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/protocol/http/Headers.java,v
>retrieving revision 1.2
>diff -u -r1.2 Headers.java
>--- gnu/java/net/protocol/http/Headers.java 18 Apr 2005 18:40:23 -0000 1.2
>+++ gnu/java/net/protocol/http/Headers.java 16 May 2005 20:59:21 -0000
>@@ -323,7 +323,10 @@
>         if (c1 == ' ' || c1 == '\t')
>           {
>             // Continuation
>-            value.append(line.substring(0, len - 1));
>+	    int last = len - 1;
>+	    if (line.charAt(last) != '\r')
>+	      ++last;
>+            value.append(line.substring(0, last));
>           }
>         else
>           {
>@@ -340,7 +343,10 @@
>                 di++;
>               }
>             while (di < len && line.charAt(di) == ' ');
>-            value.append(line.substring(di, len - 1));
>+	    int last = len - 1;
>+	    if (line.charAt(last) != '\r')
>+	      ++last;
>+            value.append(line.substring(di, last));
>           }
>       }
>   }
>  
>



More information about the Java-patches mailing list