diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/mediatype/ContentTypeCaseTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/mediatype/ContentTypeCaseTest.java new file mode 100644 index 0000000000000..7698788d50dc9 --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/mediatype/ContentTypeCaseTest.java @@ -0,0 +1,63 @@ +package io.quarkus.resteasy.reactive.server.test.mediatype; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import java.util.function.Supplier; + +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class ContentTypeCaseTest { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .setArchiveProducer(new Supplier<>() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(HelloResource.class); + } + }); + + @Test + public void test() { + given().header("test", "TeXt/Plain").get("/hello") + .then() + .statusCode(200) + .contentType("text/plain") + .body(is("text/plain")); + + given().header("test", "text/plain").get("/hello") + .then() + .statusCode(200) + .contentType("text/plain") + .body(is("text/plain")); + + given().header("test", "TEXT/PLAIN").get("/hello") + .then() + .statusCode(200) + .contentType("text/plain") + .body(is("text/plain")); + } + + @Path("hello") + public static class HelloResource { + + @GET + public Response hello(@HeaderParam("test") String contentType) { + MediaType mediaType = MediaType.valueOf(contentType); + return Response.ok(mediaType.toString()).header("content-type", mediaType).build(); + } + } +} diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java index 9a450ad606f4a..cbe8b2fb02cce 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java @@ -14,8 +14,8 @@ public class MediaTypeHeaderDelegate implements RuntimeDelegate.HeaderDelegate map = new ConcurrentHashMap(); - private static final Map reverseMap = new ConcurrentHashMap(); + private static final Map map = new ConcurrentHashMap<>(); + private static final Map reverseMap = new ConcurrentHashMap<>(); protected static boolean isValid(String str) { if (str == null || str.length() == 0) @@ -55,7 +55,7 @@ public static MediaType parse(String type) { reverseMap.clear(); } map.put(type, result); - reverseMap.put(result, type); + reverseMap.put(result, internalToString(result)); } return result; } @@ -141,10 +141,10 @@ public String toString(MediaType o) { return result; } - private String internalToString(MediaType type) { - StringBuilder buf = new StringBuilder(); + private static String internalToString(MediaType type) { + StringBuilder buf = new StringBuilder(type.getType().length() + type.getSubtype().length() + 1); - buf.append(type.getType().toLowerCase()).append("/").append(type.getSubtype().toLowerCase()); + buf.append(type.getType().toLowerCase()).append('/').append(type.getSubtype().toLowerCase()); if (type.getParameters() == null || type.getParameters().size() == 0) return buf.toString(); for (String name : type.getParameters().keySet()) {