You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/09/30 18:53:28 UTC
(tomcat) 02/08: Make the content-type checks in the AddDefaultCharsetFilter response wrapper case-insensitive as required by RFC 9110 for media types and parameter names
This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit acaf036deb07b92d3af9a38e0a1790552e7f2d07
Author: opencode <re...@apache.org>
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 4dfd1c028c..3e7a3e58b1 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 jakarta.servlet.FilterChain;
import jakarta.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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org