-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Character encoding is reset when setting Content-Type #10349
Comments
I've reproduced a problem, but after the second set I get "text/html;charset=null". Anyway, looking! |
Fix #10349 which was caused by a put of ContentType being intercepted as a remove followed by an add. The remove was incorrectly forgetting the charset without reference to the source of the charset.
@gregw So the correct state is as follows. response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("text/html"); // Content-Type after processing is "text/html;charset=utf-8"
response.setContentType("text/html"); // Content-Type after processing is "text/html;charset=null" |
This has been fixed by #10358 |
Jetty version(s)
12.0.0
Jetty Environment
ee10
Java version/vendor
(use: java -version)
OS type/version
macOS 13.4.1
Description
If the character encoding of HTTP response (
HttpServletResponse
) is set bysetCharacterEncoding
method andContent-Type
that does not include charset (e.g.text/html
) is set, the character encoding set bysetCharacterEncoding
method will be used as thecharset
ofContent-Type
.However, if you set same
Content-Type
(e.g.text/html
) again, the character encoding set bysetCharacterEncoding
method will be reset and a differentContent-Type
will be set.Checking the source code,
onRemoveField
is called when setting the set header again, but if the header isContent-Type
, the character encoding is removed. (reference)This is implemented in #9927 in
12.0.0.beta3
, so it doesn't happen in12.0.0.beta2
and earlier.How to reproduce?
Perform the following processing in Servlet.
response.setCharacterEncoding
.response.setContentType
.For example, the following code.
The text was updated successfully, but these errors were encountered: