tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters VoidOutputFilter.java IdentityInputFilter.java IdentityOutputFilter.java
Date Tue, 04 Dec 2001 06:33:07 GMT
remm        01/12/03 22:33:07

  Modified:    http11/src/java/org/apache/coyote/http11 InputFilter.java
                        InternalInputBuffer.java InternalOutputBuffer.java
                        OutputFilter.java
               http11/src/java/org/apache/coyote/http11/filters
                        IdentityInputFilter.java IdentityOutputFilter.java
  Added:       http11/src/java/org/apache/coyote/http11/filters
                        VoidOutputFilter.java
  Log:
  - Add and end method on both input and output, as some content length delimitation
    wouldn't be doable othewise when using HTTP pipelining.
  - Add a void output filter, which will be used with 204s and HEAD requests.
  
  Revision  Changes    Path
  1.4       +13 -5     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InputFilter.java
  
  Index: InputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InputFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InputFilter.java	2001/12/03 06:09:30	1.3
  +++ InputFilter.java	2001/12/04 06:33:06	1.4
  @@ -77,11 +77,7 @@
       /**
        * Read bytes.
        * 
  -     * @return If the filter does request length control, this value is
  -     * significant; it should be the number of bytes consumed from the buffer,
  -     * up until the end of the current request body, or the buffer length, 
  -     * whichever is greater. If the filter does not do request body length
  -     * control, the returned value should be -1.
  +     * @return Number of bytes read.
        */
       public int doRead(ByteChunk chunk)
           throws IOException;
  @@ -111,6 +107,18 @@
        * Set the next buffer in the filter pipeline.
        */
       public void setBuffer(InputBuffer buffer);
  +
  +
  +    /**
  +     * End the current request.
  +     * 
  +     * @return 0 is the expected return value. A positive value indicates that
  +     * too many bytes were read. This method is allowed to use buffer.doRead
  +     * to consume extra bytes. The result of this method can't be negative (if
  +     * an error happens, an IOException should be thrown instead).
  +     */
  +    public long end()
  +        throws IOException;
   
   
   }
  
  
  
  1.3       +24 -11    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java
  
  Index: InternalInputBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InternalInputBuffer.java	2001/12/03 06:09:30	1.2
  +++ InternalInputBuffer.java	2001/12/04 06:33:06	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
1.2 2001/12/03 06:09:30 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/12/03 06:09:30 $
  + * $Header: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
1.3 2001/12/04 06:33:06 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/12/04 06:33:06 $
    *
    * ====================================================================
    *
  @@ -280,7 +280,7 @@
       public void clearFilters() {
   
           filterLibrary = new InputFilter[0];
  -        lastActiveFilter = 0;
  +        lastActiveFilter = -1;
   
       }
   
  @@ -293,7 +293,7 @@
           // FIXME: Check for null ?
           // FIXME: Check index ?
   
  -        if (lastActiveFilter == 0) {
  +        if (lastActiveFilter == -1) {
               filter.setBuffer(inputStreamInputBuffer);
           } else {
               filter.setBuffer(activeFilters[lastActiveFilter]);
  @@ -319,7 +319,7 @@
           buf = headerBuffer1;
           lastValid = 0;
           pos = 0;
  -        lastActiveFilter = 0;
  +        lastActiveFilter = -1;
           parsingHeader = true;
   
       }
  @@ -351,17 +351,30 @@
           buf = newHeaderBuf;
   
           // Recycle filters
  -        if (lastActiveFilter > 0) {
  -            for (int i = 0; i < lastActiveFilter; i++) {
  -                activeFilters[i].recycle();
  -            }
  +        for (int i = 0; i <= lastActiveFilter; i++) {
  +            activeFilters[i].recycle();
           }
   
           // Reset pointers
           lastValid = lastValid - pos;
           pos = 0;
  -        lastActiveFilter = 0;
  +        lastActiveFilter = -1;
           parsingHeader = true;
  +
  +    }
  +
  +
  +    /**
  +     * End request (consumes leftover bytes).
  +     * 
  +     * @throws IOException an undelying I/O error occured
  +     */
  +    public void endRequest()
  +        throws IOException {
  +
  +        for (int i = 0; i <= lastActiveFilter; i++) {
  +            pos -= activeFilters[i].end();
  +        }
   
       }
   
  
  
  
  1.4       +10 -8     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java
  
  Index: InternalOutputBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InternalOutputBuffer.java	2001/12/03 06:09:30	1.3
  +++ InternalOutputBuffer.java	2001/12/04 06:33:06	1.4
  @@ -256,7 +256,7 @@
       public void clearFilters() {
   
           filterLibrary = new OutputFilter[0];
  -        lastActiveFilter = 0;
  +        lastActiveFilter = -1;
   
       }
   
  @@ -269,7 +269,7 @@
           // FIXME: Check for null ?
           // FIXME: Check index ?
   
  -        if (lastActiveFilter == 0) {
  +        if (lastActiveFilter == -1) {
               filter.setBuffer(outputStreamOutputBuffer);
           } else {
               filter.setBuffer(activeFilters[lastActiveFilter]);
  @@ -294,7 +294,7 @@
           outputStream = null;
           buf = headerBuffer;
           pos = 0;
  -        lastActiveFilter = 0;
  +        lastActiveFilter = -1;
           committed = false;
   
       }
  @@ -314,15 +314,13 @@
           buf = headerBuffer;
   
           // Recycle filters
  -        if (lastActiveFilter > 0) {
  -            for (int i = 0; i < lastActiveFilter; i++) {
  -                activeFilters[i].recycle();
  -            }
  +        for (int i = 0; i <= lastActiveFilter; i++) {
  +            activeFilters[i].recycle();
           }
   
           // Reset pointers
           pos = 0;
  -        lastActiveFilter = 0;
  +        lastActiveFilter = -1;
           committed = false;
   
       }
  @@ -345,6 +343,10 @@
   
               commit();
   
  +        }
  +
  +        for (int i = lastActiveFilter; i >= 0; i--) {
  +            activeFilters[i].end();
           }
   
       }
  
  
  
  1.4       +13 -18    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/OutputFilter.java
  
  Index: OutputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/OutputFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OutputFilter.java	2001/12/03 06:09:30	1.3
  +++ OutputFilter.java	2001/12/04 06:33:06	1.4
  @@ -92,24 +92,6 @@
   
   
       /**
  -     * Flush the internal buffer of the filter (if any).
  -     */
  -    /*
  -      public int flush(ByteChunk chunk)
  -      throws IOException;
  -    */
  -
  -
  -    /**
  -     * Called when ending the request.
  -     */
  -    /*
  -      public int close(ByteChunk chunk)
  -      throws IOException;
  -    */
  -
  -
  -    /**
        * Make the filter ready to process the next request.
        */
       public void recycle();
  @@ -125,6 +107,19 @@
        * Set the next buffer in the filter pipeline.
        */
       public void setBuffer(OutputBuffer buffer);
  +
  +
  +    /**
  +     * End the current request. It is acceptable to write extra bytes using
  +     * buffer.doWrite during the execution of this method.
  +     * 
  +     * @return Should return 0 unless the filter does some content length 
  +     * delimitation, in which case the number is the amount of extra bytes or
  +     * missing bytes, which would indicate an error. 
  +     * Note: It is recommended that extra bytes be swallowed by the filter.
  +     */
  +    public long end()
  +        throws IOException;
   
   
   }
  
  
  
  1.3       +13 -0     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
  
  Index: IdentityInputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IdentityInputFilter.java	2001/12/03 06:09:30	1.2
  +++ IdentityInputFilter.java	2001/12/04 06:33:07	1.3
  @@ -194,6 +194,19 @@
   
   
       /**
  +     * End the current request.
  +     */
  +    public long end()
  +        throws IOException {
  +
  +        // FIXME: Consume extra bytes.
  +        // FIXME: If too many bytes were read, return the amount.
  +        return 0;
  +
  +    }
  +
  +
  +    /**
        * Set the next buffer in the filter pipeline.
        */
       public void setBuffer(InputBuffer buffer) {
  
  
  
  1.3       +6 -25     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java
  
  Index: IdentityOutputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IdentityOutputFilter.java	2001/12/03 06:09:30	1.2
  +++ IdentityOutputFilter.java	2001/12/04 06:33:07	1.3
  @@ -197,36 +197,17 @@
   
   
       /**
  -     * Don't do anything in particular when flushing.
  +     * End the current request. It is acceptable to write extra bytes using
  +     * buffer.doWrite during the execution of this method.
        */
  -    /*
  -    public int flush(ByteChunk chunk)
  +    public long end()
           throws IOException {
  -        return doWrite(chunk);
  -    }
  -    */
  -
  -
  -    /**
  -     * Write the remaining bytes, and check that the number of bytes written
  -     * is correct.
  -     */
  -    /*
  -    public int close(ByteChunk chunk)
  -        throws IOException {
  -
  -        int n = doWrite(chunk);
  -
  -        if (remaining > 0) {
  -            // FIXME: Throw an exception if the number of bytes written is less
  -            // than the advertised content length.
  -            throw new IOException();
  -        }
   
  -        return n;
  +        if (remaining > 0)
  +            return remaining;
  +        return 0;
   
       }
  -    */
   
   
       /**
  
  
  
  1.1                  jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/VoidOutputFilter.java
  
  Index: VoidOutputFilter.java
  ===================================================================
  /*
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.coyote.http11.filters;
  
  import java.io.IOException;
  
  import org.apache.tomcat.util.buf.ByteChunk;
  
  import org.apache.coyote.OutputBuffer;
  import org.apache.coyote.Response;
  import org.apache.coyote.http11.OutputFilter;
  
  /**
   * Void output filter, which silently swallows bytes written. Used with a 204
   * status (no content) or a HEAD request.
   * 
   * @author Remy Maucherat
   */
  public class VoidOutputFilter implements OutputFilter {
  
  
      // -------------------------------------------------------------- Constants
  
  
      protected static final String ENCODING_NAME = "void";
      protected static final ByteChunk ENCODING = new ByteChunk();
  
  
      // ----------------------------------------------------- Static Initializer
  
  
      static {
          ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Next buffer in the pipeline.
       */
      protected OutputBuffer buffer;
  
  
      // --------------------------------------------------- OutputBuffer Methods
  
  
      /**
       * Write some bytes.
       * 
       * @return number of bytes written by the filter
       */
      public int doWrite(ByteChunk chunk)
          throws IOException {
  
          return chunk.getLength();
  
      }
  
  
      // --------------------------------------------------- OutputFilter Methods
  
  
      /**
       * Some filters need additional parameters from the response. All the 
       * necessary reading can occur in that method, as this method is called
       * after the response header processing is complete.
       */
      public void setResponse(Response response) {
      }
  
  
      /**
       * Set the next buffer in the filter pipeline.
       */
      public void setBuffer(OutputBuffer buffer) {
          this.buffer = buffer;
      }
  
  
      /**
       * Make the filter ready to process the next request.
       */
      public void recycle() {
      }
  
  
      /**
       * Return the name of the associated encoding; Here, the value is 
       * "identity".
       */
      public ByteChunk getEncodingName() {
          return ENCODING;
      }
  
  
      /**
       * End the current request. It is acceptable to write extra bytes using
       * buffer.doWrite during the execution of this method.
       * 
       * @return Should return 0 unless the filter does some content length 
       * delimitation, in which case the number is the amount of extra bytes or
       * missing bytes, which would indicate an error. 
       * Note: It is recommended that extra bytes be swallowed by the filter.
       */
      public long end()
          throws IOException {
          return 0;
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message