Skip to content
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

Issue #4719 Keep previous charencoding if not set in content type #4720

Merged
merged 4 commits into from
Mar 31, 2020

Conversation

janbartel
Copy link
Contributor

Closes #4719

Signed-off-by: Jan Bartel <janb@webtide.com>
@janbartel janbartel added Specification For all industry Specifications (IETF / Servlet / etc) TCK For various Specification Test Compatibility Kits (eg: Servlet, WebSocket, HTTP/2, etc) labels Mar 26, 2020
@janbartel janbartel requested a review from gregw March 26, 2020 11:44
@janbartel janbartel self-assigned this Mar 26, 2020
Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions about this one.

Does this preservation persist through dispatches?
What about error processing? does the charset persist there as well?
How does someone remove the charset on the response's Content-Type after the fact now?
What happens if the user uses HttpServletResponse.reset() after the charset has been set?

@janbartel
Copy link
Contributor Author

@joakime the change doesn't affect any of those things. All it does, is ensure that setContentType() without a char set doesn't change the existing value of the character encoding. As Request has setCharacterEncoding() method and a setContentType() method, the char set can be independent of the content-type. Previously we were treating the content-type and char-set as always inextricably linked, even if setContentType() didn't explicitly pass in a char-set (we used the defaults from MimeType).

Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this change makes the HTTP response include the charset line when we don't want it, then this is going to break many libraries (like REST / Jersey / Jax-RS).

@@ -624,7 +635,7 @@ public void testResetContentTypeWithCharacterEncoding() throws Exception

response.setContentType("wrong/answer;charset=utf-8");
response.setContentType("foo/bar");
assertEquals("foo/bar", response.getContentType());
assertEquals("foo/bar;charset=utf-8", response.getContentType());
Copy link
Contributor

@joakime joakime Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this get sent over the wire on HTTP/1.1 as ...

Content-Type: foo/bar; charset=utf-8

?

If so, then this PR is either doing too much, or we lack the extra tests to prove that we allow a user to turn off that charset= portion on the HTTP response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change won't force a change to the charset: in fact, the change prevents a change to the charset that that spec does not support. Unfortunately, the javadoc for ServletResponse.setContentType() does not make this behaviour clear in the case of the content-type without char-set, so all we have to go on is the tck test: https://github.com/eclipse-ee4j/jakartaee-tck/blob/master/src/com/sun/ts/tests/servlet/api/common/response/ResponseTests.java#L680

Copy link
Contributor

@joakime joakime Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new branch (from this one) called jetty-10.0.x-4719-keepcharencoding-extratests with new testcases to show the concern (see commit e0b322f).

Two of the new testcases in ResponseHeadersTest are now failing ...

  • testCharsetChangeToJsonMimeType()
  • testCharsetChangeToJsonMimeTypeSetCharsetToNull()

Interesting aside, I didn't know you could use HttpServletResponse.reset() after obtaining a getWriter() and still use that writer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joakime I've merged your branch into mine, and added a fix for content types like json that must have an assumed char set. Thanks for the concrete tests!!

joakime and others added 3 commits March 26, 2020 14:19
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Minor formatting and more comments.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
…ssumed

Signed-off-by: Jan Bartel <janb@webtide.com>
Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@janbartel janbartel merged commit 3f7d04f into jetty-10.0.x Mar 31, 2020
@joakime joakime deleted the jetty-10.0.x-4719-keepcharencoding branch May 21, 2020 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Specification For all industry Specifications (IETF / Servlet / etc) TCK For various Specification Test Compatibility Kits (eg: Servlet, WebSocket, HTTP/2, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ContentType with no char encoding should use previous char encoding
3 participants