Fix missing request body for GET and DELETE JdkClientHttpRequest

This commit fixes a regression introduced in gh-34971 where GET and
DELETE requests would not allow request bodies anymore for
`JdkClientHttpRequest`.
We are now using `builder.GET()` and `builder.DELETE()` methods only if
the provided body is null.

Fixes gh-35068
This commit is contained in:
Brian Clozel
2025-06-17 17:19:21 +02:00
parent 103a7e58bb
commit 45d887f973
2 changed files with 36 additions and 25 deletions
@@ -93,10 +93,21 @@ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
}
}
@Test // gh-35068
void deleteRequestWithBody() throws Exception {
URI uri = URI.create(baseUrl + "/echo");
ClientHttpRequest request = this.factory.createRequest(uri, HttpMethod.DELETE);
StreamUtils.copy("body", StandardCharsets.ISO_8859_1, request.getBody());
try (ClientHttpResponse response = request.execute()) {
assertThat(response.getStatusCode()).as("Invalid response status").isEqualTo(HttpStatus.OK);
assertThat(StreamUtils.copyToString(response.getBody(), StandardCharsets.ISO_8859_1))
.as("Invalid request body").isEqualTo("body");
}
}
@Test // gh-34971
@EnabledForJreRange(min = JRE.JAVA_19) // behavior fixed in Java 19
void requestContentLengthHeader() throws Exception {
void requestContentLengthHeaderWhenNoBody() throws Exception {
URI uri = URI.create(baseUrl + "/header/Content-Length");
assertNoContentLength(uri, HttpMethod.GET);
assertNoContentLength(uri, HttpMethod.DELETE);