Bug 61917 - AddDefaultCharsetFilter only supports text/* response
Summary: AddDefaultCharsetFilter only supports text/* response
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.5.24
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-19 07:03 UTC by Fuwei Chin
Modified: 2021-06-22 09:07 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fuwei Chin 2017-12-19 07:03:40 UTC
Overview:
I want to use AddDefaultCharsetFilter as a generic purpose filter not only for type text/* but also for type application/json, appliation/javascript, etc.

Steps to Reproduce:
1) Adding a filter registeration in web.xml
<filter>
	<filter-name>AddDefaultCharset</filter-name>
	<filter-class>org.apache.catalina.filters.AddDefaultCharsetFilter</filter-class>
	<init-param>
		<param-name>encoding</param-name>
		<param-value>UTF-8</param-value>
	</init-param>
</filter>
<filter-mapping>
	<filter-name>AddDefaultCharset</filter-name>
	<servlet-name>default</servlet-name>
</filter-mapping>

2. Requesting a static json(e.g. /test.json) resource

Actual Results:
No default charset added in response header 'Content-Type'.
(AddDefaultCharsetFilter only adds default charset for type 'text/*')

Expected Results:
Add default charset for specified types.
response types which will be processed by AddDefaultCharsetFilter can be specified through a init-param (e.g. with name 'accept' and with value 'application/json,text/*'),
if the init-param not present, use defaut value 'text/*'
Comment 1 Remy Maucherat 2017-12-19 07:20:45 UTC
As documented, the filter applies to text/* resources, so your expectation is wrong and this is a possible enhancement.
Comment 2 Konstantin Kolinko 2017-12-19 11:37:47 UTC
Please note that you have to adhere to specifications.

The mime-types have official specifications for them and are registered with IANA,
https://www.iana.org/assignments/media-types/media-types.xhtml

The application/json mime-type DOES NOT have charset parameter,
https://www.iana.org/assignments/media-types/application/json

The application/javascript has charset parameter,
though I am not sure whether it is actually respected by clients.
https://www.iana.org/assignments/media-types/application/javascript
https://tools.ietf.org/html/rfc4329#section-4.1
Comment 3 Christopher Schultz 2017-12-19 16:17:54 UTC
I'm -0 on supporting a change to add default charsets to MIME types other than text/* because those types (non-RFC) "should not" have them.

On the other hand, sometimes the only way to make this stuff work with certain clients is to specify the charset for a MIME type that isn't supposed to support it (e.g. application/json). I won't stop anyone from doing it, but it will just make services continue to refuse to adhere to standards if we support something like this.
Comment 4 Mark Thomas 2021-06-22 09:07:40 UTC
Note: enhancement request withdrawn by the original reporter.