remm        02/03/11 19:48:58

  Modified:    coyote/src/java/org/apache/coyote/tomcat4 OutputBuffer.java
  Log:
  - Fix a problem where the content-lenght calculated would be incorrect. The
    bug only happend when using a writer and the total response length was
    between 8K and 16K (since there's a buffer for bytes, and one for chars).
    This would cause the response to get truncated, as the content-length
    would get set to 8K.
    Now, the char buffer is flushed first, and if the response is still not committed
    the content-length will be set.
  - Thanks to Jon Stevens for testing with Scarab (which looks quite good and
    appears to work fine with that patch).
  
  Revision  Changes    Path
  1.7       +12 -13    
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/OutputBuffer.java
  
  Index: OutputBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/OutputBuffer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- OutputBuffer.java 11 Mar 2002 07:16:33 -0000      1.6
  +++ OutputBuffer.java 12 Mar 2002 03:48:58 -0000      1.7
  @@ -189,12 +189,6 @@
       private boolean suspended = false;
   
   
  -    /**
  -     * True if the total response size can be computed.
  -     */
  -    private boolean knownResponseSize = false;
  -
  -
       // ----------------------------------------------------------- Constructors
   
   
  @@ -295,8 +289,6 @@
           gotEnc = false;
           enc = null;
   
  -        knownResponseSize = false;
  -
       }
   
   
  @@ -312,8 +304,18 @@
           if (suspended)
               return;
   
  -        if (!coyoteResponse.isCommitted()) {
  -            knownResponseSize = true;
  +        if ((!coyoteResponse.isCommitted()) 
  +            && (coyoteResponse.getContentLength() == -1)) {
  +            // Flushing the char buffer
  +            if (state == CHAR_STATE) {
  +                cb.flushBuffer();
  +                state = BYTE_STATE;
  +            }
  +            // If this didn't cause a commit of the response, the final content
  +            // length can be calculated
  +            if (!coyoteResponse.isCommitted()) {
  +                coyoteResponse.setContentLength(bb.getLength());
  +            }
           }
   
           flush();
  @@ -370,9 +372,6 @@
               return;
           if (coyoteResponse == null)
               return;
  -
  -        if ((knownResponseSize) && (coyoteResponse.getContentLength() == -1))
  -            coyoteResponse.setContentLength(cnt);
   
           // If we really have something to write
           if (cnt > 0) {
  
  
  

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

Reply via email to