Index: build.properties.sample
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/http11/build.properties.sample,v
retrieving revision 1.2
diff -u -r1.2 build.properties.sample
--- build.properties.sample 15 Mar 2002 05:36:02 -0000 1.2
+++ build.properties.sample 7 Oct 2003 07:39:41 -0000
@@ -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
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/http11/build.xml,v
retrieving revision 1.14
diff -u -r1.14 build.xml
--- build.xml 4 May 2003 21:12:01 -0000 1.14
+++ build.xml 7 Oct 2003 07:39:41 -0000
@@ -38,6 +38,7 @@
+
@@ -82,6 +83,7 @@
+
Index: src/java/org/apache/coyote/http11/Http11Processor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
retrieving revision 1.81
diff -u -r1.81 Http11Processor.java
--- src/java/org/apache/coyote/http11/Http11Processor.java 1 Oct 2003 10:22:15 -0000 1.81
+++ src/java/org/apache/coyote/http11/Http11Processor.java 7 Oct 2003 07:39:42 -0000
@@ -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
Index: src/java/org/apache/coyote/http11/Http11Protocol.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java,v
retrieving revision 1.40
diff -u -r1.40 Http11Protocol.java
--- src/java/org/apache/coyote/http11/Http11Protocol.java 1 Oct 2003 10:24:47 -0000 1.40
+++ src/java/org/apache/coyote/http11/Http11Protocol.java 7 Oct 2003 07:39:42 -0000
@@ -103,6 +103,7 @@
setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
+ setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
}
/**
@@ -256,6 +257,7 @@
*/
private String compression = "off";
private String noCompressionUserAgents = null;
+ private String restrictedUserAgents = null;
private String compressableMimeTypes = "text/html,text/xml,text/plain";
private int compressionMinSize = 2048;
@@ -332,6 +334,11 @@
setAttribute("compression", valueS);
}
+ public void setRestrictedUserAgents(String valueS) {
+ restrictedUserAgents = valueS;
+ setAttribute("restrictedUserAgents", valueS);
+ }
+
public void setNoCompressionUserAgents(String valueS) {
noCompressionUserAgents = valueS;
setAttribute("noCompressionUserAgents", valueS);
@@ -492,6 +499,7 @@
processor.setCompressionMinSize( proto.compressionMinSize);
processor.setNoCompressionUserAgents( proto.noCompressionUserAgents);
processor.setCompressableMimeTypes( proto.compressableMimeTypes);
+ processor.setRestrictedUserAgents( proto.restrictedUserAgents);
processor.setSocketBuffer( proto.socketBuffer );
thData[Http11Protocol.THREAD_DATA_PROCESSOR]=processor;