diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/NoContentResponseTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/NoContentResponseTest.java new file mode 100644 index 0000000000000..3010ea959cee5 --- /dev/null +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/NoContentResponseTest.java @@ -0,0 +1,65 @@ +package io.quarkus.rest.client.reactive; + +import static io.quarkus.rest.client.reactive.RestClientTestUtil.setUrlForClass; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.io.InputStream; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class NoContentResponseTest { + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(Client.class, Resource.class) + .addAsResource( + new StringAsset(setUrlForClass(Client.class)), + "application.properties")); + + @RestClient + Client client; + + @Test + public void testGetStreamNoContent() { + assertNull(client.getStream()); + } + + @Test + public void testGetResponseNoContent() { + Response response = client.getResponse(); + assertFalse(response.hasEntity()); + assertNull(response.getEntity()); + } + + @Path("/test") + @RegisterRestClient + @Produces(MediaType.TEXT_PLAIN) + interface Client { + @GET + InputStream getStream(); + + @GET + Response getResponse(); + } + + @Path("/test") + static class Resource { + @GET + public Response get() { + return Response.noContent().build(); + } + } +} diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSetResponseEntityRestHandler.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSetResponseEntityRestHandler.java index 4e4f5745ad57e..8b3236f4951e2 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSetResponseEntityRestHandler.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSetResponseEntityRestHandler.java @@ -9,6 +9,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.StatusType; +import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.client.api.WebClientApplicationException; import org.jboss.resteasy.reactive.client.impl.ClientRequestContextImpl; import org.jboss.resteasy.reactive.client.impl.ClientResponseContextImpl; @@ -36,6 +37,12 @@ public void handle(RestClientRequestContext context) throws Exception { // so we have to write it, but without filters/interceptors if (isAbortedWith(requestContext)) { propagateAbortedWithEntityToResponse(context); + } else { + StatusType effectiveResponseStatus = determineEffectiveResponseStatus(context, requestContext); + if ((effectiveResponseStatus.getStatusCode() == RestResponse.Status.NO_CONTENT.getStatusCode()) + && (requestContext != null && !requestContext.hasEntity())) { + context.setResponseEntityStream(null); + } } }