(tomcat) branch main updated: Fix matching of the pattern documented in the javadoc
[email protected] Fri, 31 Jul 2026 09:36:08 +0000
| Newsgroups | gmane.comp.jakarta.tomcat.devel |
|---|---|
| Message-ID | <178549056798.3714835.13521840249108973163@gitbox3-he-fi.apache.org> |
This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 1f29baf341 Fix matching of the pattern documented in the javadoc
1f29baf341 is described below
commit 1f29baf341220048c66e30aedf43c5b7d0266060
Author: remm <[email protected]>
AuthorDate: Fri Jul 31 11:35:54 2026 +0200
Fix matching of the pattern documented in the javadoc
Also add a test case for the noCompressionUserAgents feature, coauthored
with OpenCode.
---
java/org/apache/coyote/CompressionConfig.java | 2 +-
.../coyote/TestCompressionConfigUserAgents.java | 67 ++++++++++++++++++++++
webapps/docs/changelog.xml | 6 ++
3 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/coyote/CompressionConfig.java b/java/org/apache/coyote/CompressionConfig.java
index 7c5efcfec9..b07b8c10b5 100644
--- a/java/org/apache/coyote/CompressionConfig.java
+++ b/java/org/apache/coyote/CompressionConfig.java
@@ -375,7 +375,7 @@ public class CompressionConfig {
MessageBytes userAgentValueMB = request.getMimeHeaders().getValue("user-agent");
if (userAgentValueMB != null) {
String userAgentValue = userAgentValueMB.toString();
- if (noCompressionUserAgents.matcher(userAgentValue).matches()) {
+ if (noCompressionUserAgents.matcher(userAgentValue).find()) {
return false;
}
}
diff --git a/test/org/apache/coyote/TestCompressionConfigUserAgents.java b/test/org/apache/coyote/TestCompressionConfigUserAgents.java
new file mode 100644
index 0000000000..43f988533f
--- /dev/null
+++ b/test/org/apache/coyote/TestCompressionConfigUserAgents.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestCompressionConfigUserAgents {
+
+ @Test
+ public void testNoCompressionUserAgents() {
+ CompressionConfig config = new CompressionConfig();
+ config.setNoCompressionUserAgents("gorilla|MSIE|tigrus");
+
+ Request request = new Request();
+ request.getMimeHeaders().addValue("accept-encoding").setString("gzip");
+ Response response;
+
+ // Force mode (compressionLevel == 2) skips the user-agent check,
+ // so use "on" mode where the check applies
+ config.setCompression("on");
+
+ // User-agent matching the pattern should not be compressed
+ response = createResponse();
+ request.getMimeHeaders().addValue("user-agent").setString("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
+ Assert.assertFalse(config.useCompression(request, response));
+
+ // No user-agent header should be compressed
+ response = createResponse();
+ request.getMimeHeaders().removeHeader("user-agent");
+ Assert.assertTrue(config.useCompression(request, response));
+
+ // User-agent not matching the pattern should be compressed
+ response = createResponse();
+ request.getMimeHeaders().removeHeader("user-agent");
+ request.getMimeHeaders().addValue("user-agent").setString("Mozilla/5.0 (X11; Linux x86_64)");
+ Assert.assertTrue(config.useCompression(request, response));
+
+ // Force mode skips the user-agent check
+ response = createResponse();
+ config.setCompression("force");
+ request.getMimeHeaders().removeHeader("user-agent");
+ request.getMimeHeaders().addValue("user-agent").setString("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
+ Assert.assertTrue(config.useCompression(request, response));
+ }
+
+ private Response createResponse() {
+ Response response = new Response();
+ response.setContentLength(4096);
+ response.setContentType("text/html");
+ return response;
+ }
+}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 173f38f99e..f550280459 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -339,6 +339,12 @@
of how early in the HEADERS frame processing an error is detected.
(markt)
</fix>
+ <fix>
+ Fix matching the compression config
+ <code>noCompressionUserAgents</code> with patterns of the style
+ of the example <code>gorilla|desesplorer|tigrus</code> pattern
+ documented in the javadoc. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">