Set "reuse" flag of final AJP "END_RESPONSE"
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 29 Jul 2011 22:08:20 +0000 (22:08 +0000)
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 29 Jul 2011 22:08:20 +0000 (22:08 +0000)
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.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1152385 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/ajp/AbstractAjpProcessor.java
java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpNioProcessor.java
java/org/apache/coyote/ajp/AjpProcessor.java
webapps/docs/changelog.xml

index 04a0f55..9ee30e8 100644 (file)
@@ -63,6 +63,7 @@ public abstract class AbstractAjpProcessor<S> extends AbstractProcessor<S> {
      * End message array.
      */
     protected static final byte[] endMessageArray;
+    protected static final byte[] endAndCloseMessageArray;
 
 
     /**
@@ -88,6 +89,16 @@ public abstract class AbstractAjpProcessor<S> extends AbstractProcessor<S> {
         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();
index 96ded17..6efd594 100644 (file)
@@ -299,10 +299,16 @@ public class AjpAprProcessor extends AbstractAjpProcessor<Long> {
         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);
 
     }
index 4ce2ee8..84cab13 100644 (file)
@@ -319,7 +319,13 @@ public class AjpNioProcessor extends AbstractAjpProcessor<NioChannel> {
         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);
     }
 
 
index 35b77b3..ceb1c29 100644 (file)
@@ -313,7 +313,7 @@ public class AjpProcessor extends AbstractAjpProcessor<Socket> {
         finished = true;
 
         // Add the end message
-        output.write(endMessageArray);
+        output.write(error ? endAndCloseMessageArray : endMessageArray);
 
     }
 
index 9a08ccf..2ae9e9c 100644 (file)
         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">