Skip to content

Commit

Permalink
Only add charset to application media types
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Oct 30, 2024
1 parent f91f180 commit 9857831
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import jakarta.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.common.util.MediaTypeHelper;
import org.jboss.resteasy.reactive.server.spi.ContentType;

/**
Expand All @@ -22,7 +21,9 @@ public EncodedMediaType(MediaType mediaType) {
MediaType effectiveMediaType = mediaType;
String effectiveCharset;
String originalCharset = mediaType.getParameters().get("charset");
if (MediaTypeHelper.isTextLike(mediaType)) {
String subtype = mediaType.getSubtype();
if (mediaType.getType().equals("application") && (subtype.contains("json")
|| subtype.contains("xml") || subtype.contains("yaml"))) {
effectiveCharset = originalCharset;
if (effectiveCharset == null) {
effectiveCharset = StandardCharsets.UTF_8.name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testMatch() throws Exception {
WebTarget base = client.target(generateURL("/match"));
Response response = base.request().header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.get();
Assertions.assertEquals("text/html;charset=UTF-8", response.getHeaders().getFirst("Content-Type"));
Assertions.assertEquals("text/html", response.getHeaders().getFirst("Content-Type"));
String res = response.readEntity(String.class);
Assertions.assertEquals("*/*", res, "Wrong response content");
response.close();
Expand Down

0 comments on commit 9857831

Please sign in to comment.