Patch committed

Oleg

On Fri, 2003-03-21 at 15:02, Kalnichevski, Oleg wrote:
> The patch fixes RFC 822 non-compliant line termination problem reported by Carl A. 
> Dunham
> 
> Cheers
> 
> Oleg
> 
> 
> Index: java/org/apache/commons/httpclient/HttpMethodBase.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
> retrieving revision 1.123
> diff -u -r1.123 HttpMethodBase.java
> --- java/org/apache/commons/httpclient/HttpMethodBase.java    13 Mar 2003 17:51:28 
> -0000      1.123
> +++ java/org/apache/commons/httpclient/HttpMethodBase.java    21 Mar 2003 13:52:16 
> -0000
> @@ -1980,7 +1980,7 @@
>                  + " \"HTTP/\"");
>          }
>          if (Wire.enabled()) {
> -            Wire.input(statusString);
> +            Wire.input(statusString + "\r\n");
>          }
>          //create the status line from the status string
>          statusLine = new StatusLine(statusString);
> Index: java/org/apache/commons/httpclient/HttpParser.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpParser.java,v
> retrieving revision 1.3
> diff -u -r1.3 HttpParser.java
> --- java/org/apache/commons/httpclient/HttpParser.java        28 Feb 2003 12:48:58 
> -0000      1.3
> +++ java/org/apache/commons/httpclient/HttpParser.java        21 Mar 2003 13:52:15 
> -0000
> @@ -28,10 +28,10 @@
>  
>      /**
>       * Return byte array from an (unchunked) input stream.
> -     * Stop reading when <tt>"\r\n"</tt> terminator encountered 
> +     * Stop reading when <tt>"\n"</tt> terminator encountered 
>       * If the stream ends before the line terminator is found,
> -     * the last part of the string will still be returned.
> -     * '\r' and '\n' are allowed to appear individually in the stream.
> +     * the last part of the string will still be returned. 
> +     * If no input data available, <code>null</code> is returned
>       *
>       * @param inputStream the stream to read from
>       *
> @@ -39,21 +39,14 @@
>       * @return a byte array from the stream
>       */
>      public static byte[] readRawLine(InputStream inputStream) throws IOException {
> -        LOG.trace("enter HttpConnection.readRawLine()");
> +        LOG.trace("enter HttpParser.readRawLine()");
>  
>          ByteArrayOutputStream buf = new ByteArrayOutputStream();
>          int ch;
>          while ((ch = inputStream.read()) >= 0) {
>              buf.write(ch);
> -            if (ch == '\r') {
> -                ch = inputStream.read();
> -                if (ch < 0) {
> -                    break;
> -                }
> -                buf.write(ch);
> -                if (ch == '\n') {
> -                    break;
> -                }
> +            if (ch == '\n') {
> +                break;
>              }
>          }
>          if (buf.size() == 0) {
> @@ -63,10 +56,10 @@
>      }
>  
>      /**
> -     * Read up to <tt>"\r\n"</tt> from an (unchunked) input stream.
> +     * Read up to <tt>"\n"</tt> from an (unchunked) input stream.
>       * If the stream ends before the line terminator is found,
>       * the last part of the string will still be returned.
> -     * '\r' and '\n' are allowed to appear individually in the stream.
> +     * If no input data available, <code>null</code> is returned
>       *
>       * @param inputStream the stream to read from
>       *
> @@ -75,17 +68,24 @@
>       */
>  
>      public static String readLine(InputStream inputStream) throws IOException {
> -        LOG.trace("enter HttpConnection.readLine()");
> +        LOG.trace("enter HttpParser.readLine()");
>          byte[] rawdata = readRawLine(inputStream);
>          if (rawdata == null) {
>              return null;
>          }
>          int len = rawdata.length;
> -        if (( len >= 2) && (rawdata[len - 2] == '\r') && (rawdata[len - 1] == 
> '\n')) {
> -            return HttpConstants.getString(rawdata, 0, rawdata.length - 2);
> -        } else {
> -            return HttpConstants.getString(rawdata);
> +        int offset = 0;
> +        if (len > 0) {
> +            if (rawdata[len - 1] == '\n') {
> +                offset++;
> +                if (len > 1) {
> +                    if (rawdata[len - 2] == '\r') {
> +                        offset++;
> +                    }
> +                }
> +            }
>          }
> +        return HttpConstants.getString(rawdata, 0, len - offset);
>      }
>  
>      /**
> 
> 
> ______________________________________________________________________
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to