tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http SocketInputStream.java
Date Sat, 02 Dec 2000 03:51:31 GMT
remm        00/12/01 19:51:31

  Modified:    catalina/src/share/org/apache/catalina/connector/http
                        SocketInputStream.java
  Log:
  - The IS is now more tolerant when parsing the HTTP header. It now doesn't
    require that CRLF to end a line (LF is enough), as is recommended in the
    HTTP spec for improved robustness. Note that a client which would do that
    is actually not compliant with the spec, and needs to be fixed.
  - Removed some old test code.
  
  Revision  Changes    Path
  1.4       +18 -200   jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java
  
  Index: SocketInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SocketInputStream.java	2000/11/22 02:28:19	1.3
  +++ SocketInputStream.java	2000/12/02 03:51:31	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
1.3 2000/11/22 02:28:19 remm Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/11/22 02:28:19 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
1.4 2000/12/02 03:51:31 remm Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/12/02 03:51:31 $
    *
    * ====================================================================
    * 
  @@ -164,13 +164,13 @@
           
           // Checking for a blank line
           int chr = 0;
  -        while ((chr = read()) == CR) { // Skipping CR
  -            read(); // Skipping LF
  -        }
  +        do { // Skipping CR or LF
  +            chr = read();
  +        } while ((chr == CR) || (chr == LF));
           if (chr == -1)
               throw new EOFException
                   (sm.getString("requestStream.readline.error"));
  -        if (chr != CR) {
  +        if ((chr != CR) || (chr != LF)) {
               pos--;
           }
   
  @@ -263,8 +263,6 @@
           readStart = pos;
           readCount = 0;
           
  -        int crPos = -2;
  -        
           boolean eol = false;
           
           while (!eol) {
  @@ -285,12 +283,6 @@
               if (pos >= count) {
                   // Copying part (or all) of the internal buffer to the line
                   // buffer
  -                if (pos != readStart) {
  -                    // Hack to reintialize the internal buffer. We pretend the 
  -                    // first character was never read and we'll reread it from
  -                    // the buffer.
  -                    crPos = crPos - count;
  -                }
                   int val = read();
                   if (val == -1)
                       throw new IOException
  @@ -299,17 +291,17 @@
                   readStart = 0;
               }
               if (buf[pos] == CR) {
  -                // We found a CR. Next character has to be a LF.
  -                crPos = pos;
  -            } else if ((buf[pos] == LF) && (crPos == (pos - 1))) {
  +                // Skip CR.
  +            } else if (buf[pos] == LF) {
                   eol = true;
  +            } else {
  +                requestLine.protocol[readCount] = (char) buf[pos];
  +                readCount++;
               }
  -            requestLine.protocol[readCount] = (char) buf[pos];
  -            readCount++;
               pos++;
           }
           
  -        requestLine.protocolEnd = readCount - 2;
  +        requestLine.protocolEnd = readCount;
           
       }
   
  @@ -332,8 +324,10 @@
               header.recycle();
           
           // Checking for a blank line
  -        if (read() == CR) { // Skipping CR
  -            read(); // Skipping LF
  +        int chr = read();
  +        if ((chr == CR) || (chr == LF)) { // Skipping CR
  +            if (chr == CR)
  +                read(); // Skipping LF
               header.nameEnd = 0;
               header.valueEnd = 0;
               return;
  @@ -441,12 +435,6 @@
                   if (pos >= count) {
                       // Copying part (or all) of the internal buffer to the line
                       // buffer
  -                    if (pos != readStart) {
  -                        // Hack to reintialize the internal buffer. 
  -                        // We pretend the first character was never read and 
  -                        // we'll reread it from the buffer.
  -                        crPos = crPos - count;
  -                    }
                       int val = read();
                       if (val == -1)
                           throw new IOException
  @@ -455,9 +443,7 @@
                       readStart = 0;
                   }
                   if (buf[pos] == CR) {
  -                    // We found a CR. Next character has to be a LF.
  -                    crPos = pos;
  -                } else if ((buf[pos] == LF) && (crPos == (pos - 1))) {
  +                } else if (buf[pos] == LF) {
                       eol = true;
                   } else {
                       // FIXME : Check if binary conversion is working fine
  @@ -495,174 +481,6 @@
           header.valueEnd = readCount;
           
       }
  -
  -
  -    /**
  -     * Read a line, and copies it to the given buffer. This function is meant
  -     * to be used during the HTTP request header parsing. Do NOT attempt to 
  -     * read the request body using it.
  -     * 
  -     * @param buffer char buffer
  -     * @return the number of bytes read
  -     * @throws IOException If an exception occurs during the underlying socket
  -     * read operations, or if the given buffer is not big enough to accomodate
  -     * the whole line.
  -     */
  -    public int readLine(char[] buffer) 
  -        throws IOException {
  -        return readLine(buffer, 0);
  -    }
  -
  -
  -    /**
  -     * Read a line, and copies it to the given buffer. This function is meant
  -     * to be used during the HTTP request header parsing. Do NOT attempt to 
  -     * read the request body using it. Read data must be US-ASCII.
  -     * 
  -     * @param buffer char buffer
  -     * @param startPos position in the buffer from which the read character
  -     * will be copied
  -     * @return the number of bytes read
  -     * @throws IOException If an exception occurs during the underlying socket
  -     * read operations, or if the given buffer is not big enough to accomodate
  -     * the whole line.
  -     */
  -    public int readLine(char[] buffer, int startPos) 
  -        throws IOException {
  -        int maxRead = buffer.length - startPos;
  -        int readStart = pos;
  -        int readCount = 0;
  -        int bufferPos = startPos;
  -        
  -        int crPos = -2;
  -        
  -        boolean eol = false;
  -        
  -        while (!eol && (readCount < maxRead)) {
  -            
  -            // We're at the end of the internal buffer
  -            if (pos >= count) {
  -                // Copying part (or all) of the internal buffer to the line
  -                // buffer
  -                if (pos != readStart) {
  -                    // Hack to reintialize the internal buffer. We pretend the 
  -                    // first character was never read and we'll reread it from
  -                    // the buffer.
  -                    crPos = crPos - count;
  -                }
  -                int val = read();
  -                if (val == -1)
  -                    throw new IOException
  -                        (sm.getString("requestStream.readline.error"));
  -                pos = 0;
  -                readStart = 0;
  -            }
  -            if (buf[pos] == CR) {
  -                // We found a CR. Next character has to be a LF.
  -                crPos = pos;
  -            } else if ((buf[pos] == LF) && (crPos == (pos - 1))) {
  -                eol = true;
  -            }
  -            buffer[startPos + readCount] = (char) buf[pos];
  -            readCount++;
  -            pos++;
  -        }
  -        
  -        if (readCount == maxRead)
  -            throw new IOException
  -                (sm.getString("requestStream.readline.toolong"));
  -        
  -        return readCount - 2;
  -    }
  -
  -
  -    /**
  -     * Read a line, and copies it to the given buffer. This function is meant
  -     * to be used during the HTTP request header parsing. Do NOT attempt to 
  -     * read the request body using it.
  -     * 
  -     * @param buffer byte buffer
  -     * @return the number of bytes read
  -     * @throws IOException If an exception occurs during the underlying socket
  -     * read operations, or if the given buffer is not big enough to accomodate
  -     * the whole line.
  -     */
  -    public int readLine(byte[] buffer) 
  -        throws IOException {
  -        return readLine(buffer, 0);
  -    }
  -
  -
  -    /**
  -     * Read a line, and copies it to the given buffer. This function is meant
  -     * to be used during the HTTP request header parsing. Do NOT attempt to 
  -     * read the request body using it.
  -     * 
  -     * @param buffer byte buffer
  -     * @param startPos position in the buffer from which the read character
  -     * will be copied
  -     * @return the number of bytes read
  -     * @throws IOException If an exception occurs during the underlying socket
  -     * read operations, or if the given buffer is not big enough to accomodate
  -     * the whole line.
  -     */
  -    public int readLine(byte[] buffer, int startPos) 
  -        throws IOException {
  -        int maxRead = buffer.length - startPos;
  -        int readStart = pos;
  -        int readCount = 0;
  -        int bufferPos = startPos;
  -        
  -        int crPos = -2;
  -        
  -        boolean eol = false;
  -        
  -        while (!eol && (readCount < maxRead)) {
  -            
  -            // We're at the end of the internal buffer
  -            if (pos >= count) {
  -                // Copying part (or all) of the internal buffer to the line
  -                // buffer
  -                if (pos != readStart) {
  -                    System.arraycopy(buf, readStart, buffer, bufferPos, 
  -                                     pos - readStart);
  -                    // Hack to reintialize the internal buffer. We pretend the 
  -                    // first character was never read and we'll reread it from
  -                    // the buffer.
  -                    crPos = crPos - count;
  -                    bufferPos += pos - readStart;
  -                }
  -                int val = read();
  -                if (val == -1)
  -                    throw new IOException
  -                        (sm.getString("requestStream.readline.error"));
  -                pos = 0;
  -                readStart = 0;
  -            }
  -            if (buf[pos] == CR) {
  -                // We found a CR. Next character has to be a LF.
  -                crPos = pos;
  -            } else if ((buf[pos] == LF) && (crPos == (pos - 1))) {
  -                eol = true;
  -                // Copy the line from the buffer
  -                if ((pos - 1 - readStart) > 0)
  -                    System.arraycopy
  -                        (buf, readStart, buffer, bufferPos, 
  -                         pos - 1 - readStart);
  -            }
  -            readCount++;
  -            pos++;
  -        }
  -        
  -        if (readCount == maxRead)
  -            throw new IOException
  -                (sm.getString("requestStream.readline.toolong"));
  -        
  -        return readCount - 2;
  -    }
  -
  -
  -    // ------------------------------------------------------ Protected Methods
   
   
   }
  
  
  

Mime
View raw message