From f070cb852fb8f3aaf4d2cef52aadecefc5dac01f Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 11 Dec 2023 08:48:52 +0200 Subject: [PATCH] Remove unnecessary content type checks These checks have potentially already been performed in ClassRoutingHandler Closes: #37637 --- .../server/core/ResteasyReactiveRequestContext.java | 12 ++++++++++++ .../server/handlers/ClassRoutingHandler.java | 2 ++ .../server/handlers/FixedProducesHandler.java | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java index 2248a8f7763ac5..3db35defa7d121 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java @@ -796,6 +796,18 @@ public void initPathSegments() { } } + private static final String PRODUCES_CHECKED_PROPERTY_KEY = AbstractResteasyReactiveContext.CUSTOM_RR_PROPERTIES_PREFIX + + "ProducesChecked"; + + public void setProducesChecked(boolean checked) { + setProperty(PRODUCES_CHECKED_PROPERTY_KEY, checked); + } + + public boolean isProducesChecked() { + Object val = getProperty(PRODUCES_CHECKED_PROPERTY_KEY); + return val != null && (boolean) val; + } + @Override public Object getHeader(String name, boolean single) { if (httpHeaders == null) { diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java index df1d6de283c35b..1b8fdc9b901d7e 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java @@ -141,6 +141,8 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE); } } + + requestContext.setProducesChecked(true); } requestContext.restart(target.value); diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/FixedProducesHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/FixedProducesHandler.java index 8029481fc125c9..2a0f15307447e9 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/FixedProducesHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/FixedProducesHandler.java @@ -36,7 +36,7 @@ public FixedProducesHandler(MediaType mediaType, EntityWriter writer) { @Override public void handle(ResteasyReactiveRequestContext requestContext) throws Exception { List acceptValues = (List) requestContext.getHeader(HttpHeaders.ACCEPT, false); - if (acceptValues.isEmpty()) { + if (acceptValues.isEmpty() || requestContext.isProducesChecked()) { requestContext.setResponseContentType(mediaType); requestContext.setEntityWriter(writer); } else {