You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/04/28 13:18:33 UTC

svn commit: r1676477 - in /tomcat/trunk: java/org/apache/coyote/http11/AbstractHttp11Protocol.java java/org/apache/coyote/http11/Http11Processor.java webapps/docs/config/http.xml

Author: markt
Date: Tue Apr 28 11:18:32 2015
New Revision: 1676477

URL: http://svn.apache.org/r1676477
Log:
Refactor compressableMimeType
Convert comma separated string to string array once and re-use it rather than converting for every new Processor

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
    tomcat/trunk/webapps/docs/config/http.xml

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java?rev=1676477&r1=1676476&r2=1676477&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java Tue Apr 28 11:18:32 2015
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.servlet.http.HttpUpgradeHandler;
@@ -131,16 +132,29 @@ public abstract class AbstractHttp11Prot
     }
 
 
-    private String compressableMimeTypes = "text/html,text/xml,text/plain";
-    public String getCompressableMimeType() { return compressableMimeTypes; }
+    private String compressableMimeType = "text/html,text/xml,text/plain";
+    private String[] compressableMimeTypes = null;
+    public String getCompressableMimeType() { return compressableMimeType; }
     public void setCompressableMimeType(String valueS) {
-        compressableMimeTypes = valueS;
+        compressableMimeType = valueS;
+        compressableMimeTypes = null;
     }
-    public String getCompressableMimeTypes() {
-        return getCompressableMimeType();
-    }
-    public void setCompressableMimeTypes(String valueS) {
-        setCompressableMimeType(valueS);
+    public String[] getCompressableMimeTypes() {
+        String[] result = compressableMimeTypes;
+        if (result != null) {
+            return result;
+        }
+        List<String> values = new ArrayList<>();
+        StringTokenizer tokens = new StringTokenizer(compressableMimeType, ",");
+        while (tokens.hasMoreTokens()) {
+            String token = tokens.nextToken().trim();
+            if (token.length() > 0) {
+                values.add(token);
+            }
+        }
+        result = values.toArray(new String[values.size()]);
+        compressableMimeTypes = result;
+        return result;
     }
 
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1676477&r1=1676476&r2=1676477&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Tue Apr 28 11:18:32 2015
@@ -21,7 +21,6 @@ import java.io.InterruptedIOException;
 import java.nio.ByteBuffer;
 import java.util.Locale;
 import java.util.Set;
-import java.util.StringTokenizer;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.regex.Pattern;
 
@@ -201,11 +200,11 @@ public class Http11Processor extends Abs
      */
     protected Pattern noCompressionUserAgents = null;
 
+
     /**
-     * List of MIMES which could be gzipped
+     * List of MIMES for which compression may be enabled.
      */
-    protected String[] compressableMimeTypes =
-    { "text/html", "text/xml", "text/plain" };
+    protected String[] compressableMimeTypes;
 
 
     /**
@@ -320,18 +319,6 @@ public class Http11Processor extends Abs
         }
     }
 
-    /**
-     * Add a mime-type which will be compressible
-     * The mime-type String will be exactly matched
-     * in the response mime-type header .
-     *
-     * @param mimeType mime-type string
-     */
-    public void addCompressableMimeType(String mimeType) {
-        compressableMimeTypes =
-            addStringArray(compressableMimeTypes, mimeType);
-    }
-
 
     /**
      * Set compressible mime-type list (this method is best when used with
@@ -344,24 +331,6 @@ public class Http11Processor extends Abs
 
 
     /**
-     * Set compressable mime-type list
-     * List contains users agents separated by ',' :
-     *
-     * ie: "text/html,text/xml,text/plain"
-     */
-    public void setCompressableMimeTypes(String compressableMimeTypes) {
-        if (compressableMimeTypes != null) {
-            this.compressableMimeTypes = null;
-            StringTokenizer st = new StringTokenizer(compressableMimeTypes, ",");
-
-            while (st.hasMoreTokens()) {
-                addCompressableMimeType(st.nextToken().trim());
-            }
-        }
-    }
-
-
-    /**
      * Return compression level.
      */
     public String getCompression() {
@@ -377,29 +346,6 @@ public class Http11Processor extends Abs
     }
 
 
-    /**
-     * General use method
-     *
-     * @param sArray the StringArray
-     * @param value string
-     */
-    private String[] addStringArray(String sArray[], String value) {
-        String[] result = null;
-        if (sArray == null) {
-            result = new String[1];
-            result[0] = value;
-        }
-        else {
-            result = new String[sArray.length + 1];
-            for (int i = 0; i < sArray.length; i++) {
-                result[i] = sArray[i];
-            }
-            result[sArray.length] = value;
-        }
-        return result;
-    }
-
-
     /**
      * Checks if any entry in the string array starts with the specified value
      *

Modified: tomcat/trunk/webapps/docs/config/http.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/http.xml?rev=1676477&r1=1676476&r2=1676477&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/http.xml (original)
+++ tomcat/trunk/webapps/docs/config/http.xml Tue Apr 28 11:18:32 2015
@@ -329,7 +329,8 @@
     <attribute name="compressableMimeType" required="false">
       <p>The value is a comma separated list of MIME types for which HTTP
       compression may be used.
-      The default value is <code>text/html,text/xml,text/plain</code>.</p>
+      The default value is <code>text/html,text/xml,text/plain,text/css</code>.
+      </p>
     </attribute>
 
     <attribute name="compression" required="false">



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