costin      01/08/23 21:38:50

  Modified:    src/share/org/apache/tomcat/modules/server
                        Ajp13Interceptor.java
               src/facade22/org/apache/tomcat/facade
                        ServletInputStreamFacade.java
  Log:
  Part of the changes to support chunked input stream. Keith - sorry I didn't wait
  for your patch, but I wanted to test it - and I'm going to run watchdogs and
  tests anyway, better to have those in too.
  
  Revision  Changes    Path
  1.11      +9 -3      
jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp13Interceptor.java
  
  Index: Ajp13Interceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp13Interceptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Ajp13Interceptor.java     2001/08/12 03:57:52     1.10
  +++ Ajp13Interceptor.java     2001/08/24 04:38:50     1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp13Interceptor.java,v
 1.10 2001/08/12 03:57:52 costin Exp $
  - * $Revision: 1.10 $
  - * $Date: 2001/08/12 03:57:52 $
  + * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp13Interceptor.java,v
 1.11 2001/08/24 04:38:50 costin Exp $
  + * $Revision: 1.11 $
  + * $Date: 2001/08/24 04:38:50 $
    *
    * ====================================================================
    *
  @@ -220,6 +220,9 @@
       
       public int doRead() throws IOException 
       {
  +     if( contentLength == -1 ) {
  +         return ajp13.doRead();
  +     }
        if( available <= 0 )
            return -1;
        available--;
  @@ -228,6 +231,9 @@
       
       public int doRead(byte[] b, int off, int len) throws IOException 
       {
  +     if( contentLength == -1 ) {
  +         return ajp13.doRead(b,off,len);
  +     }
        if( available <= 0 )
            return -1;
        int rd=ajp13.doRead( b,off, len );
  
  
  
  1.5       +46 -31    
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletInputStreamFacade.java
  
  Index: ServletInputStreamFacade.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletInputStreamFacade.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServletInputStreamFacade.java     2001/08/23 11:22:25     1.4
  +++ ServletInputStreamFacade.java     2001/08/24 04:38:50     1.5
  @@ -100,34 +100,35 @@
        limit=-1;
       }
   
  -    /** Read a byte. Detect if a ByteBuffer is used, if not
  -     *  use the old method.
  -     */
  -    private int doRead() throws IOException {
  -     //System.out.println("DoRead");
  -     return reqA.doRead();
  -    }
  -
  -    private int doRead(byte[] b, int off, int len) throws IOException {
  -     return reqA.doRead(b,off,len);
  -    }
  -
       // -------------------- ServletInputStream methods 
   
       public int read() throws IOException {
  -     //      System.out.println("Read " + limit );
  -     if (limit != -1) {
  -         if (bytesRead < limit) {
  -             bytesRead++;
  -             return doRead();
  +     if( dL>0) debug("read() " + limit + " " + bytesRead );
  +     if (limit == -1) {
  +         // Ask the adapter for more data. We are in the 'no content-length'
  +         // case - i.e. chunked encoding ( acording to http spec CL is required
  +         // for everything else.
  +         int rd=reqA.doRead();
  +         if( rd<0 ) {
  +             limit=0; // no more bytes can be read.
            } else {
  -             return -1;
  +             bytesRead++; // for statistics
            }
  -     } else {
  +         return rd;
  +     }
  +
  +     // We have a limit
  +     if (bytesRead >= limit)
            return -1;
  -         // no content-length, no body
  -         //      return doRead();
  +     
  +     bytesRead++;
  +     int rd=reqA.doRead();
  +     if( rd<0 ) {
  +         limit=0; // adapter detected EOF, before C-L finished.
  +         // trust the adapter - if it returns EOF it's unlikely it'll give us
  +         // any more data
        }
  +     return rd;
       }
   
       public int read(byte[] b) throws IOException {
  @@ -135,26 +136,40 @@
       }
   
       public int read(byte[] b, int off, int len) throws IOException {
  -     if (limit != -1) {
  -         if (bytesRead == limit) {
  -             return -1;
  -         }
  -         if (bytesRead + len > limit) {
  -             len = limit - bytesRead;
  -         }
  -         int numRead = doRead(b, off, len);
  +     if( dL>0) debug("read(" +  len + ") " + limit + " " + bytesRead );
  +     if (limit == -1) {
  +         int numRead = reqA.doRead(b, off, len);
            if (numRead > 0) {
                bytesRead += numRead;
            }
  +         if( numRead< 0 ) {
  +             // EOF - stop reading
  +             limit=0;
  +         }
            return numRead;
  -     } else {
  +     }
  +
  +     if (bytesRead >= limit) {
            return -1;
  -         //return doRead(b, off, len);
        }
  +
  +     if (bytesRead + len > limit) {
  +         len = limit - bytesRead;
  +     }
  +     int numRead = reqA.doRead(b, off, len);
  +     if (numRead > 0) {
  +         bytesRead += numRead;
  +     }
  +     return numRead;
       }
       
   
       public int readLine(byte[] b, int off, int len) throws IOException {
        return super.readLine(b, off, len);
  +    }
  +
  +    private static int dL=0;
  +    private void debug( String s ) {
  +     System.out.println("ServletInputStreamFacade: " + s );
       }
   }
  
  
  

Reply via email to