commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java HttpParser.java
Date Mon, 24 Mar 2003 18:39:41 GMT
olegk       2003/03/24 10:39:41

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java HttpParser.java
  Log:
  Fixes the CRLF line termination bug reported by Carl A. Dunham
  
  http://www.mail-archive.com/commons-httpclient-dev%40jakarta.apache.org/msg01301.html
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.124     +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.123
  retrieving revision 1.124
  diff -u -r1.123 -r1.124
  --- HttpMethodBase.java	13 Mar 2003 17:51:28 -0000	1.123
  +++ HttpMethodBase.java	24 Mar 2003 18:39:40 -0000	1.124
  @@ -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);
  
  
  
  1.4       +20 -20    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpParser.java
  
  Index: HttpParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpParser.java	28 Feb 2003 12:48:58 -0000	1.3
  +++ HttpParser.java	24 Mar 2003 18:39:41 -0000	1.4
  @@ -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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message