This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit d0bfe291336339b65dba394867aef41f72ffc63a
Author: opencode <[email protected]>
AuthorDate: Wed Sep 30 16:21:37 2026 +0200

    Make the content-type checks in the AddDefaultCharsetFilter response 
wrapper case-insensitive as required by RFC 9110 for media types and parameter 
names
---
 .../catalina/filters/AddDefaultCharsetFilter.java    | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/catalina/filters/AddDefaultCharsetFilter.java 
b/java/org/apache/catalina/filters/AddDefaultCharsetFilter.java
index 9c70623cc0..119f0fe81e 100644
--- a/java/org/apache/catalina/filters/AddDefaultCharsetFilter.java
+++ b/java/org/apache/catalina/filters/AddDefaultCharsetFilter.java
@@ -18,6 +18,7 @@ package org.apache.catalina.filters;
 
 import java.io.IOException;
 import java.nio.charset.Charset;
+import java.util.Locale;
 
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -114,17 +115,20 @@ public class AddDefaultCharsetFilter extends FilterBase {
         @Override
         public void setContentType(String contentType) {
 
-            if (contentType != null && contentType.startsWith("text/")) {
-                if (!contentType.contains("charset=")) {
-                    super.setContentType(contentType + ";charset=" + encoding);
-                } else {
-                    super.setContentType(contentType);
-                    encoding = getCharacterEncoding();
+            if (contentType != null) {
+                String lowerCaseContentType = 
contentType.toLowerCase(Locale.ENGLISH);
+                if (lowerCaseContentType.startsWith("text/")) {
+                    if (!lowerCaseContentType.contains("charset=")) {
+                        super.setContentType(contentType + ";charset=" + 
encoding);
+                    } else {
+                        super.setContentType(contentType);
+                        encoding = getCharacterEncoding();
+                    }
+                    return;
                 }
-            } else {
-                super.setContentType(contentType);
             }
 
+            super.setContentType(contentType);
         }
 
         @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to