Skip to content

Commit 08a65a9

Browse files
authored
Merge pull request quarkusio#49880 from geoand/quarkusio#49879
Remove Content-Encoding header when response is 204
2 parents 2bfb611 + 705d7ed commit 08a65a9

File tree

2 files changed

+36
-0
lines changed
  • extensions/resteasy-reactive/rest/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/compress
  • independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core

2 files changed

+36
-0
lines changed

extensions/resteasy-reactive/rest/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/compress/CompressionTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import jakarta.ws.rs.Path;
99
import jakarta.ws.rs.Produces;
1010

11+
import org.hamcrest.CoreMatchers;
1112
import org.jboss.resteasy.reactive.RestResponse;
1213
import org.jboss.shrinkwrap.api.asset.StringAsset;
1314
import org.junit.jupiter.api.Test;
@@ -45,6 +46,12 @@ public void testEndpoint() {
4546
assertUncompressed("/my.doc");
4647
}
4748

49+
@Test
50+
public void noContent() {
51+
assertNoContent("/endpoint/no-content");
52+
assertNoContent("/endpoint/void-no-content");
53+
}
54+
4855
private void assertCompressed(String path) {
4956
String bodyStr = get(path).then().statusCode(200).header("Content-Encoding", "gzip").extract().asString();
5057
assertEquals(MyEndpoint.MESSAGE, bodyStr);
@@ -57,6 +64,13 @@ private void assertUncompressed(String path) {
5764
assertEquals(MyEndpoint.MESSAGE, response.asString());
5865
}
5966

67+
private static void assertNoContent(String path) {
68+
get(path)
69+
.then()
70+
.statusCode(204)
71+
.header("Content-Encoding", CoreMatchers.nullValue());
72+
}
73+
6074
@Path("endpoint")
6175
public static class MyEndpoint {
6276

@@ -121,6 +135,18 @@ public String contentTypeInProducesCompressed() {
121135
public String contentTypeInProducesUncompressed() {
122136
return MESSAGE;
123137
}
138+
139+
@GET
140+
@Path("no-content")
141+
public RestResponse<Void> noContent() {
142+
return RestResponse.noContent();
143+
}
144+
145+
@GET
146+
@Path("void-no-content")
147+
public void voidNoContent() {
148+
149+
}
124150
}
125151

126152
}

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,13 @@ public static void encodeResponseHeaders(ResteasyReactiveRequestContext requestC
484484
//there is no response, so we just set the content type
485485
if (requestContext.getResponseEntity() == null) {
486486
vertxResponse.setStatusCode(Response.Status.NO_CONTENT.getStatusCode());
487+
sanitizeNoContentResponse(vertxResponse);
487488
}
488489
EncodedMediaType contentType = requestContext.getResponseContentType();
489490
if (contentType != null) {
490491
vertxResponse.setResponseHeader(CONTENT_TYPE, contentType.toString());
491492
}
493+
492494
return;
493495
}
494496
Response response = requestContext.getResponse().get();
@@ -531,6 +533,14 @@ public static void encodeResponseHeaders(ResteasyReactiveRequestContext requestC
531533
vertxResponse.setResponseHeader(entry.getKey(), strValues);
532534
}
533535
}
536+
537+
if (response.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) {
538+
sanitizeNoContentResponse(vertxResponse);
539+
}
540+
}
541+
542+
private static void sanitizeNoContentResponse(ServerHttpResponse serverHttpResponse) {
543+
serverHttpResponse.removeResponseHeader("Content-Encoding");
534544
}
535545

536546
private static boolean requireSingleHeader(String header) {

0 commit comments

Comments
 (0)