Author: rjung
Date: Fri Jul 29 22:08:20 2011
New Revision: 1152385

URL: http://svn.apache.org/viewvc?rev=1152385&view=rev
Log:
Set "reuse" flag of final AJP "END_RESPONSE"
packet to "0" if we plan to close the connection.

mod_jk will respect it and I just committed
the same to mod_proxy_ajp in httpd trunk.

If the web server does not respect it, things do
not get worse by nevertheless setting the flag,
because the patch does not change whether we actually
close the connection or not.

Modified:
    tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1152385&r1=1152384&r2=1152385&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java Fri Jul 
29 22:08:20 2011
@@ -63,6 +63,7 @@ public abstract class AbstractAjpProcess
      * End message array.
      */
     protected static final byte[] endMessageArray;
+    protected static final byte[] endAndCloseMessageArray;
 
 
     /**
@@ -88,6 +89,16 @@ public abstract class AbstractAjpProcess
         System.arraycopy(endMessage.getBuffer(), 0, endMessageArray, 0,
                 endMessage.getLen());
 
+        // Allocate the end and close message array
+        AjpMessage endAndCloseMessage = new AjpMessage(16);
+        endAndCloseMessage.reset();
+        endAndCloseMessage.appendByte(Constants.JK_AJP13_END_RESPONSE);
+        endAndCloseMessage.appendByte(0);
+        endAndCloseMessage.end();
+        endAndCloseMessageArray = new byte[endAndCloseMessage.getLen()];
+        System.arraycopy(endAndCloseMessage.getBuffer(), 0, 
endAndCloseMessageArray, 0,
+                endAndCloseMessage.getLen());
+
         // Allocate the flush message array
         AjpMessage flushMessage = new AjpMessage(16);
         flushMessage.reset();

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=1152385&r1=1152384&r2=1152385&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Fri Jul 29 
22:08:20 2011
@@ -299,10 +299,16 @@ public class AjpAprProcessor extends Abs
         finished = true;
 
         // Add the end message
-        if (outputBuffer.position() + endMessageArray.length > 
outputBuffer.capacity()) {
+        byte[] messageArray;
+        if (error) {
+            messageArray = endAndCloseMessageArray;
+        } else {
+            messageArray = endMessageArray;
+        }
+        if (outputBuffer.position() + messageArray.length > 
outputBuffer.capacity()) {
             flush(false);
         }
-        outputBuffer.put(endMessageArray);
+        outputBuffer.put(messageArray);
         flush(false);
 
     }

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java?rev=1152385&r1=1152384&r2=1152385&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Fri Jul 29 
22:08:20 2011
@@ -319,7 +319,13 @@ public class AjpNioProcessor extends Abs
         finished = true;
 
         // Add the end message
-        output(endMessageArray, 0, endMessageArray.length);
+        byte[] messageArray;
+        if (error) {
+            messageArray = endAndCloseMessageArray;
+        } else {
+            messageArray = endMessageArray;
+        }
+        output(messageArray, 0, messageArray.length);
     }
 
 

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1152385&r1=1152384&r2=1152385&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Fri Jul 29 
22:08:20 2011
@@ -313,7 +313,7 @@ public class AjpProcessor extends Abstra
         finished = true;
 
         // Add the end message
-        output.write(endMessageArray);
+        output.write(error ? endAndCloseMessageArray : endMessageArray);
 
     }
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1152385&r1=1152384&r2=1152385&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Jul 29 22:08:20 2011
@@ -128,6 +128,10 @@
         Ensure that when using sendfile, HTTP APR sockets are not added to
         multiple pollers. This may cause errors during shutdown. (markt)
       </fix>
+      <update>
+        Set <code>reuse</code> flag of final AJP <code>END_RESPONSE</code>
+        packet to <code>0</code> if we plan to close the connection. (rjung)
+      </update>
     </changelog>
   </subsection>
   <subsection name="Jasper">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to