Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;

import org.hamcrest.CoreMatchers;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -45,6 +46,12 @@ public void testEndpoint() {
assertUncompressed("/my.doc");
}

@Test
public void noContent() {
assertNoContent("/endpoint/no-content");
assertNoContent("/endpoint/void-no-content");
}

private void assertCompressed(String path) {
String bodyStr = get(path).then().statusCode(200).header("Content-Encoding", "gzip").extract().asString();
assertEquals(MyEndpoint.MESSAGE, bodyStr);
Expand All @@ -57,6 +64,13 @@ private void assertUncompressed(String path) {
assertEquals(MyEndpoint.MESSAGE, response.asString());
}

private static void assertNoContent(String path) {
get(path)
.then()
.statusCode(204)
.header("Content-Encoding", CoreMatchers.nullValue());
}

@Path("endpoint")
public static class MyEndpoint {

Expand Down Expand Up @@ -121,6 +135,18 @@ public String contentTypeInProducesCompressed() {
public String contentTypeInProducesUncompressed() {
return MESSAGE;
}

@GET
@Path("no-content")
public RestResponse<Void> noContent() {
return RestResponse.noContent();
}

@GET
@Path("void-no-content")
public void voidNoContent() {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,13 @@ public static void encodeResponseHeaders(ResteasyReactiveRequestContext requestC
//there is no response, so we just set the content type
if (requestContext.getResponseEntity() == null) {
vertxResponse.setStatusCode(Response.Status.NO_CONTENT.getStatusCode());
sanitizeNoContentResponse(vertxResponse);
}
EncodedMediaType contentType = requestContext.getResponseContentType();
if (contentType != null) {
vertxResponse.setResponseHeader(CONTENT_TYPE, contentType.toString());
}

return;
}
Response response = requestContext.getResponse().get();
Expand Down Expand Up @@ -531,6 +533,14 @@ public static void encodeResponseHeaders(ResteasyReactiveRequestContext requestC
vertxResponse.setResponseHeader(entry.getKey(), strValues);
}
}

if (response.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) {
sanitizeNoContentResponse(vertxResponse);
}
}

private static void sanitizeNoContentResponse(ServerHttpResponse serverHttpResponse) {
serverHttpResponse.removeResponseHeader("Content-Encoding");
}

private static boolean requireSingleHeader(String header) {
Expand Down
Loading