|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
20 | 20 | import java.net.URI;
|
| 21 | +import java.nio.charset.StandardCharsets; |
21 | 22 |
|
22 | 23 | import org.jspecify.annotations.Nullable;
|
23 | 24 | import org.junit.jupiter.api.AfterAll;
|
24 | 25 | import org.junit.jupiter.api.BeforeAll;
|
25 | 26 | import org.junit.jupiter.api.Test;
|
| 27 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
| 28 | +import org.junit.jupiter.api.condition.JRE; |
26 | 29 |
|
27 | 30 | import org.springframework.http.HttpMethod;
|
28 | 31 | import org.springframework.http.HttpStatus;
|
29 | 32 | import org.springframework.http.HttpStatusCode;
|
| 33 | +import org.springframework.util.StreamUtils; |
30 | 34 |
|
31 | 35 | import static org.assertj.core.api.Assertions.assertThat;
|
32 | 36 |
|
33 | 37 | /**
|
34 | 38 | * Tests for {@link JdkClientHttpRequestFactory}.
|
35 | 39 | *
|
36 | 40 | * @author Marten Deinum
|
| 41 | + * @author Brian Clozel |
37 | 42 | */
|
38 | 43 | class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
39 | 44 |
|
@@ -91,4 +96,22 @@ public void contentLength0() throws IOException {
|
91 | 96 | }
|
92 | 97 | }
|
93 | 98 |
|
| 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 | + |
94 | 117 | }
|
0 commit comments