You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by hg...@apache.org on 2003/10/07 10:48:38 UTC

cvs commit: jakarta-tomcat-connectors/http11 build.xml build.properties.sample

hgomez      2003/10/07 01:48:38

  Modified:    http11/src/java/org/apache/coyote/http11
                        Http11Processor.java
               http11   build.xml build.properties.sample
  Log:
  Add regexp support to check for Compression/HTTP 1.1 compatible browsers.
  
  Revision  Changes    Path
  1.82      +77 -31    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java
  
  Index: Http11Processor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
  retrieving revision 1.81
  retrieving revision 1.82
  diff -u -r1.81 -r1.82
  --- Http11Processor.java	1 Oct 2003 10:22:15 -0000	1.81
  +++ Http11Processor.java	7 Oct 2003 08:48:37 -0000	1.82
  @@ -81,6 +81,8 @@
   import org.apache.coyote.http11.filters.IdentityOutputFilter;
   import org.apache.coyote.http11.filters.VoidInputFilter;
   import org.apache.coyote.http11.filters.VoidOutputFilter;
  +import org.apache.regexp.RE;
  +import org.apache.regexp.RESyntaxException;
   import org.apache.tomcat.util.buf.Ascii;
   import org.apache.tomcat.util.buf.ByteChunk;
   import org.apache.tomcat.util.buf.HexUtils;
  @@ -203,7 +205,7 @@
       /**
        * List of restricted user agents.
        */
  -    protected String[] restrictedUserAgents = null;
  +    protected RE[] restrictedUserAgents = null;
   
   
       /**
  @@ -281,9 +283,8 @@
       /**
        * List of user agents to not use gzip with
        */
  -    protected String[] noCompressionUserAgents = null;
  -
  -
  +    protected RE       noCompressionUserAgents[]     = null;
  +    
       /**
        * List of MIMES which could be gzipped
        */
  @@ -364,7 +365,10 @@
        * @param userAgent user-agent string
        */
       public void addNoCompressionUserAgent(String userAgent) {
  -        addStringArray(noCompressionUserAgents, userAgent);
  +        try {
  +            RE nRule = new RE(userAgent);
  +            addREArray(noCompressionUserAgents, new RE(userAgent));
  +        } catch (RESyntaxException ree) {}
       }
   
   
  @@ -373,7 +377,7 @@
        * a large number of connectors, where it would be better to have all of 
        * them referenced a single array).
        */
  -    public void setNoCompressionUserAgents(String[] noCompressionUserAgents) {
  +    public void setNoCompressionUserAgents(RE[] noCompressionUserAgents) {
           this.noCompressionUserAgents = noCompressionUserAgents;
       }
   
  @@ -394,15 +398,6 @@
           }
       }
   
  -
  -    /**
  -     * Return the list of no compression user agents.
  -     */
  -    public String[] findNoCompressionUserAgents() {
  -        return (noCompressionUserAgents);
  -    }
  -
  -
       /**
        * Add a mime-type which will be compressable
        * The mime-type String will be exactly matched
  @@ -483,13 +478,38 @@
        * @param value string
        */
       private void addStringArray(String sArray[], String value) {
  -        if (sArray == null)
  -            sArray = new String[0];
  -        String[] results = new String[sArray.length + 1];
  -        for (int i = 0; i < sArray.length; i++)
  -            results[i] = sArray[i];
  -        results[sArray.length] = value;
  -        sArray = results;
  +        if (sArray == null) {
  +            sArray = new String[1];
  +            sArray[0] = value;
  +        }
  +        else {
  +            String[] results = new String[sArray.length + 1];
  +            for (int i = 0; i < sArray.length; i++)
  +                results[i] = sArray[i];
  +            results[sArray.length] = value;
  +            sArray = results;
  +        }
  +    }
  +
  +
  +    /**
  +     * General use method
  +     * 
  +     * @param rArray the REArray 
  +     * @param value Obj
  +     */
  +    private void addREArray(RE rArray[], RE value) {
  +        if (rArray == null) {
  +            rArray = new RE[1];
  +            rArray[0] = value;
  +        }    
  +        else {    
  +            RE[] results = new RE[rArray.length + 1];
  +            for (int i = 0; i < rArray.length; i++)
  +                results[i] = rArray[i];
  +            results[rArray.length] = value;
  +            rArray = results;
  +        }
       }
   
   
  @@ -529,13 +549,16 @@
   
       /**
        * Add restricted user-agent (which will downgrade the connector 
  -     * to HTTP/1.0 mode). The user agent String given will be exactly matched
  -     * to the user-agent header submitted by the client.
  +     * to HTTP/1.0 mode). The user agent String given will be matched
  +     * via regexp to the user-agent header submitted by the client.
        * 
        * @param userAgent user-agent string
        */
       public void addRestrictedUserAgent(String userAgent) {
  -        addStringArray(restrictedUserAgents, userAgent);
  +        try {
  +            RE nRule = new RE(userAgent);
  +            addREArray(restrictedUserAgents, new RE(userAgent));
  +        } catch (RESyntaxException ree) {}
       }
   
   
  @@ -544,16 +567,37 @@
        * a large number of connectors, where it would be better to have all of 
        * them referenced a single array).
        */
  -    public void setRestrictedUserAgents(String[] restrictedUserAgents) {
  +    public void setRestrictedUserAgents(RE[] restrictedUserAgents) {
           this.restrictedUserAgents = restrictedUserAgents;
       }
   
  +    /**
  +     * Set restricted user agent list (which will downgrade the connector
  +     * to HTTP/1.0 mode). List contains users agents separated by ',' :
  +     * 
  +     * ie: "gorilla,desesplorer,tigrus"
  +     */
  +    public void setRestrictedUserAgents(String restrictedUserAgents) {
  +        if (restrictedUserAgents != null) {
  +            StringTokenizer st = new StringTokenizer(restrictedUserAgents, ",");
  +        
  +            while (st.hasMoreTokens()) {
  +                addRestrictedUserAgent(st.nextToken().trim());
  +            }
  +        }
  +    }
  +
   
       /**
        * Return the list of restricted user agents.
        */
       public String[] findRestrictedUserAgents() {
  -        return (restrictedUserAgents);
  +        String[] sarr = new String [restrictedUserAgents.length];
  +        
  +        for (int i = 0; i < restrictedUserAgents.length; i++)
  +            sarr[i] = restrictedUserAgents[i].toString();
  +            
  +        return (sarr);
       }
   
   
  @@ -1055,9 +1099,10 @@
               // and keepAlive flags accordingly
               String userAgentValue = userAgentValueMB.toString();
               for (int i = 0; i < restrictedUserAgents.length; i++) {
  -                if (restrictedUserAgents[i].equals(userAgentValue)) {
  +                if (restrictedUserAgents[i].match(userAgentValue)) {
                       http11 = false;
                       keepAlive = false;
  +                    break;
                   }
               }
           }
  @@ -1273,9 +1318,10 @@
                   request.getMimeHeaders().getValue("user-agent");
               String userAgentValue = userAgentValueMB.toString();
   
  -            // TODO: Use regexp instead of simple string compare (cf: Apache 2.x)
  -            if (inStringArray(noCompressionUserAgents, userAgentValue))
  -                return false;
  +            // If one Regexp rule match, disable compression
  +            for (int i = 0; i < noCompressionUserAgents.length; i++)
  +                if (noCompressionUserAgents[i].match(userAgentValue))
  +                    return false;
           }
   
           // Check if suffisant len to trig the compression        
  
  
  
  1.15      +3 -1      jakarta-tomcat-connectors/http11/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/build.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- build.xml	4 May 2003 21:12:01 -0000	1.14
  +++ build.xml	7 Oct 2003 08:48:37 -0000	1.15
  @@ -38,6 +38,7 @@
     <property name="jmx.jar" location="../lib/mx4j.jar" />
     <property name="commons-modeler.jar" location="../../jakarta-commons/modeler/dist/commons-modeler.jar" />
     <property name="commons-logging.jar" value="../lib/commons-logging.jar" />
  +  <property name="regexp.jar" value="../lib/jakarta-regexp-1.2.jar" />
   
   <!-- ========== Component Declarations ==================================== -->
   
  @@ -82,6 +83,7 @@
       <pathelement location="${tomcat-coyote.jar}"/>
       <pathelement location="${commons-logging.jar}"/>
       <pathelement location="${commons-modeler.jar}"/>
  +    <pathelement location="${regexp.jar}"/>
       <pathelement location="${jmx.jar}"/>
     </path>
   
  
  
  
  1.3       +5 -2      jakarta-tomcat-connectors/http11/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/build.properties.sample,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.properties.sample	15 Mar 2002 05:36:02 -0000	1.2
  +++ build.properties.sample	7 Oct 2003 08:48:37 -0000	1.3
  @@ -31,4 +31,7 @@
   junit.jar=/java/junit/junit.jar
   
   # commons-logging.jar -- Commons Logging 1.0 package
  -commons-logging.jar=../lib/commons-logging.jar
  \ No newline at end of file
  +commons-logging.jar=../lib/commons-logging.jar
  +
  +# ----- Jakarta Regular Expressions Library, version 1.2 -----
  +regexp.jar=../lib/jakarta-regexp-1.2.jar
  
  
  

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