Compress outgoing response headers according to the
authormturk <mturk@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 26 Nov 2006 09:29:15 +0000 (09:29 +0000)
committermturk <mturk@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 26 Nov 2006 09:29:15 +0000 (09:29 +0000)
AJP13 protocol specification.

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

java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpProcessor.java
java/org/apache/coyote/ajp/Constants.java

index dda1cef..3ce901d 100644 (file)
@@ -960,9 +960,15 @@ public class AjpAprProcessor implements ActionHook {
         // Other headers
         int numHeaders = headers.size();
         responseHeaderMessage.appendInt(numHeaders);
-        for (int i = 0; i < numHeaders; i++) {
+        for (int i = 0; i < numHeaders; i++) {            
             MessageBytes hN = headers.getName(i);
-            responseHeaderMessage.appendBytes(hN);
+            int hC = Constants.getResponseAjpIndex(hN.toString());
+            if (hC > 0) {
+                responseHeaderMessage.appendInt(hC);
+            }
+            else {
+                responseHeaderMessage.appendBytes(hN);
+            }
             MessageBytes hV=headers.getValue(i);
             responseHeaderMessage.appendBytes(hV);
         }
index b06d216..2161f2e 100644 (file)
@@ -929,7 +929,13 @@ public class AjpProcessor implements ActionHook {
         responseHeaderMessage.appendInt(numHeaders);
         for (int i = 0; i < numHeaders; i++) {
             MessageBytes hN = headers.getName(i);
-            responseHeaderMessage.appendBytes(hN);
+            int hC = Constants.getResponseAjpIndex(hN.toString());
+            if (hC > 0) {
+                responseHeaderMessage.appendInt(hC);
+            }
+            else {
+                responseHeaderMessage.appendBytes(hN);
+            }
             MessageBytes hV=headers.getValue(i);
             responseHeaderMessage.appendBytes(hV);
         }
index 6074b49..21bef8d 100644 (file)
@@ -17,6 +17,9 @@
 
 package org.apache.coyote.ajp;
 
+import java.lang.IndexOutOfBoundsException;
+import java.util.Hashtable;
+import java.util.Locale;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 
@@ -67,6 +70,7 @@ public final class Constants {
     public static final int SC_RESP_SERVLET_ENGINE      = 0xA009;
     public static final int SC_RESP_STATUS              = 0xA00A;
     public static final int SC_RESP_WWW_AUTHENTICATE    = 0xA00B;
+    public static final int SC_RESP_AJP13_MAX           = 11;
 
     // Integer codes for common (optional) request attribute names
     public static final byte SC_A_CONTEXT       = 1;  // XXX Unused
@@ -179,7 +183,47 @@ public final class Constants {
             "user-agent"
     };
 
+    // Translates integer codes to response header names
+    public static final String []responseTransArray = {
+            "content-type",
+            "content-language",
+            "content-length",
+            "date",
+            "last-modified",
+            "location",
+            "set-cookie",
+            "set-cookie2",
+            "servlet-engine",
+            "status",
+            "www-authenticate"
+    };
 
+    private static final Hashtable<String,Integer>  responseTransHash =
+        new Hashtable<String,Integer>(20);
+
+    static {
+        try {
+            int i;
+            for (i = 0; i < SC_RESP_AJP13_MAX; i++) {
+                responseTransHash.put(responseTransArray[i],
+                                      new Integer(0xA001 + i));
+            }
+        }
+        catch (Exception e) {
+            // Do nothing
+        }
+    }    
+
+    public static final int getResponseAjpIndex(String header)
+    {
+        Integer i = responseTransHash.get(header.toLowerCase(Locale.US));
+        if (i == null)
+            return 0;
+        else
+            return i.intValue();
+    }
+
+    
     /**
      * CRLF.
      */