-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
RESTEasy Reactive shouldn't forcefully append a charset
attribute when media-type is application/json
#43998
Comments
/cc @FroMage (rest), @geoand (rest), @stuartwdouglas (rest) |
Perhaps it should not forcibly add that Interestingly https://www.ietf.org/rfc/rfc4627.html#section-3 says it can indeed only be unicode, I never realised that. Good to know. Good that we enforce it to be utf8 (regardless of whether or not we set the Also interestingly, it could be utf8 or utf-16 or utf-32, in which case we need an extra https://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html header set to |
Hey @FroMage
That's my opinion.
It makes Quarkus not compatible with code like So you're left with 2 choices for the producer side:
IMO, even if the second type of recipients are not correct as per the spec, I expect them to be way more common because |
Oh, I wasn't aware of that. And I fail to see the rationale as the encoding can be inferred from the first 4 bytes, as described here: https://www.ietf.org/rfc/rfc4627.html#section-3. You can check what Jackson does: you don't need to pass a Charset when parsing in InputStream, it just infers it. 🤷 |
Seems OK to me to not add a charset for json, given all this. Depending on whether @geoand agrees. |
We originally added it because of #25295 |
@geoand Indeed. The thing is that you can't handle all media-types the same way. What we did in Gatling is treating |
Right, that does seem to make sense and I actually think were doing something similar, I see: if (MediaTypeHelper.isTextLike(mediaType)) {
effectiveCharset = originalCharset;
if (effectiveCharset == null) {
effectiveCharset = StandardCharsets.UTF_8.name();
}
} where public static boolean isTextLike(MediaType mediaType) {
String type = mediaType.getType();
String subtype = mediaType.getSubtype();
return (type.equals("application") && (subtype.contains("json") || subtype.contains("xml") || subtype.contains("yaml")))
|| type.equals("text");
} So I guess we just need to not use @FroMage WDYT? |
LGTM |
Using handheld Gson.toJson() here instead of relying on Jax-RS negotiation because of quarkusio/quarkus#43998 (as Chrome JavaScript fetch() seems to be troubled by the non-compliant ';charset=UTF-8' extension added to Content-Type: application/json by Quarkus)
Describe the bug
When computing a
content-type
header, RESTEasy Reactive shouldn't forcefully append acharset
attribute to all text based media-types, includingapplication/json
.It was not originally the case, this change was introduced by this commit: 60aa2b7
As per the IANA spec for application/json:
This can be interpreted in several ways I guess. I interpret it as:
The reason behind this is that JSON requires either UTF-8, UTF-16 or UTF-32 encoding and parsers are expected to detect the correct encoding based on the first bytes.
Expected behavior
content-type: application/json
Actual behavior
content-type: application/json;charset=UTF-8
How to Reproduce?
https://github.com/quarkusio/quarkus/blob/3.15.1/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/mediatype/CharsetTest.java#L56
Output of
uname -a
orver
irrelevant
Output of
java -version
irrelevant
Quarkus version or git rev
3.15.1
Build tool (ie. output of
mvnw --version
orgradlew --version
)irrelevant
Additional information
Note: this broke our Keycloak client when we upgraded because it was strict. We fix it and made it lenient but I still think this is also a server side issue and
charset
shouldn't be there.The text was updated successfully, but these errors were encountered: