Skip to content

Commit d75f20f

Browse files
committed
Merge branch '6.2.x'
2 parents a16cdd2 + 659472f commit d75f20f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,16 @@ private HttpRequest buildRequest(HttpHeaders headers, @Nullable Body body) {
149149
}
150150
});
151151

152-
builder.method(this.method.name(), bodyPublisher(headers, body));
152+
switch (this.method.name()) {
153+
case "GET" :
154+
builder.GET();
155+
break;
156+
case "DELETE" :
157+
builder.DELETE();
158+
break;
159+
default :
160+
builder.method(this.method.name(), bodyPublisher(headers, body));
161+
}
153162
return builder.build();
154163
}
155164

spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,27 @@
1818

1919
import java.io.IOException;
2020
import java.net.URI;
21+
import java.nio.charset.StandardCharsets;
2122

2223
import org.jspecify.annotations.Nullable;
2324
import org.junit.jupiter.api.AfterAll;
2425
import org.junit.jupiter.api.BeforeAll;
2526
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.condition.EnabledForJreRange;
28+
import org.junit.jupiter.api.condition.JRE;
2629

2730
import org.springframework.http.HttpMethod;
2831
import org.springframework.http.HttpStatus;
2932
import org.springframework.http.HttpStatusCode;
33+
import org.springframework.util.StreamUtils;
3034

3135
import static org.assertj.core.api.Assertions.assertThat;
3236

3337
/**
3438
* Tests for {@link JdkClientHttpRequestFactory}.
3539
*
3640
* @author Marten Deinum
41+
* @author Brian Clozel
3742
*/
3843
class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
3944

@@ -91,4 +96,22 @@ public void contentLength0() throws IOException {
9196
}
9297
}
9398

99+
100+
@Test // gh-34971
101+
@EnabledForJreRange(min = JRE.JAVA_19) // behavior fixed in Java 19
102+
void requestContentLengthHeader() throws Exception {
103+
URI uri = URI.create(baseUrl + "/header/Content-Length");
104+
assertNoContentLength(uri, HttpMethod.GET);
105+
assertNoContentLength(uri, HttpMethod.DELETE);
106+
}
107+
108+
protected void assertNoContentLength(URI uri, HttpMethod method) throws Exception {
109+
ClientHttpRequest request = factory.createRequest(uri, method);
110+
try (ClientHttpResponse response = request.execute()) {
111+
assertThat(response.getStatusCode()).as("Invalid response status").isEqualTo(HttpStatus.OK);
112+
assertThat(StreamUtils.copyToString(response.getBody(), StandardCharsets.ISO_8859_1))
113+
.as("Invalid Content-Length request header").isEqualTo("Content-Length:null");
114+
}
115+
}
116+
94117
}

0 commit comments

Comments
 (0)