From d25df944e8f55fb4a216e72e2cbc0b7693471bb0 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 | 9 +++++++++ .../reactive/server/handlers/ClassRoutingHandler.java | 2 ++ .../reactive/server/handlers/FixedProducesHandler.java | 2 +- 3 files changed, 12 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 2248a8f7763ac..2821582f8cd01 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 @@ -135,6 +135,7 @@ public abstract class ResteasyReactiveRequestContext private OutputStream outputStream; private OutputStream underlyingOutputStream; private FormData formData; + private boolean producesChecked; public ResteasyReactiveRequestContext(Deployment deployment, ThreadSetupAction requestContext, ServerRestHandler[] handlerChain, ServerRestHandler[] abortHandlerChain) { @@ -796,6 +797,14 @@ public void initPathSegments() { } } + public void setProducesChecked(boolean checked) { + producesChecked = checked; + } + + public boolean isProducesChecked() { + return producesChecked; + } + @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 df1d6de283c35..1b8fdc9b901d7 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 8029481fc125c..2a0f15307447e 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 {