mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Clean HTTP response headers after decompression in JDK client
Prior to this commit, gh-35225 introduced HTTP response body decompression support for "gzip" and "deflate" encodings for the `JdkClientHttpRequestFactory`. While body decompression works, the client keeps the "Content-Encoding" and "Content-Length" response headers intact, which misleads further response handling: the body size has changed and it is not compressed anymore. This commit ensures that the relevant response headers are removed from the HTTP response after decompression. Fixes gh-35668
This commit is contained in:
+1
@@ -136,6 +136,7 @@ public abstract class AbstractMockWebServerTests {
|
||||
.body(buffer)
|
||||
.code(200);
|
||||
builder.setHeader(HttpHeaders.CONTENT_ENCODING, encoding);
|
||||
builder.setHeader(HttpHeaders.CONTENT_LENGTH, buffer.size());
|
||||
return builder.build();
|
||||
}
|
||||
return new MockResponse.Builder().code(404).build();
|
||||
|
||||
+6
-2
@@ -135,7 +135,9 @@ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
assertThat(response.getStatusCode()).as("Invalid response status").isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.getHeaders().getFirst("Content-Encoding"))
|
||||
.as("Invalid content encoding").isEqualTo("gzip");
|
||||
.as("Content Encoding should be removed").isNull();
|
||||
assertThat(response.getHeaders().getFirst("Content-Length"))
|
||||
.as("Content-Length should be removed").isNull();
|
||||
assertThat(response.getBody()).as("Invalid request body").hasContent("Payload to compress");
|
||||
}
|
||||
}
|
||||
@@ -150,7 +152,9 @@ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
assertThat(response.getStatusCode()).as("Invalid response status").isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.getHeaders().getFirst("Content-Encoding"))
|
||||
.as("Invalid content encoding").isEqualTo("deflate");
|
||||
.as("Content Encoding should be removed").isNull();
|
||||
assertThat(response.getHeaders().getFirst("Content-Length"))
|
||||
.as("Content-Length should be removed").isNull();
|
||||
assertThat(response.getBody()).as("Invalid request body").hasContent("Payload to compress");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user