Merge branch '6.2.x'

This commit is contained in:
Brian Clozel
2025-06-02 15:48:19 +02:00
2 changed files with 33 additions and 1 deletions

View File

@@ -149,7 +149,16 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
}
});
builder.method(this.method.name(), bodyPublisher(headers, body));
switch (this.method.name()) {
case "GET" :
builder.GET();
break;
case "DELETE" :
builder.DELETE();
break;
default :
builder.method(this.method.name(), bodyPublisher(headers, body));
}
return builder.build();
}

View File

@@ -18,15 +18,19 @@ package org.springframework.http.client;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.util.StreamUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link JdkClientHttpRequestFactory}.
*
* @author Marten Deinum
* @author Brian Clozel
*/
class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
@@ -91,4 +96,22 @@ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
}
}
@Test // gh-34971
@EnabledForJreRange(min = JRE.JAVA_19) // behavior fixed in Java 19
void requestContentLengthHeader() throws Exception {
URI uri = URI.create(baseUrl + "/header/Content-Length");
assertNoContentLength(uri, HttpMethod.GET);
assertNoContentLength(uri, HttpMethod.DELETE);
}
protected void assertNoContentLength(URI uri, HttpMethod method) throws Exception {
ClientHttpRequest request = factory.createRequest(uri, method);
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 Content-Length request header").isEqualTo("Content-Length:null");
}
}
}