|
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.junit.jupiter.api.AfterAll; |
23 | 24 | import org.junit.jupiter.api.BeforeAll; |
24 | 25 | import org.junit.jupiter.api.Test; |
| 26 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
| 27 | +import org.junit.jupiter.api.condition.JRE; |
25 | 28 |
|
26 | 29 | import org.springframework.http.HttpMethod; |
27 | 30 | import org.springframework.http.HttpStatus; |
28 | 31 | import org.springframework.http.HttpStatusCode; |
29 | 32 | import org.springframework.lang.Nullable; |
| 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 |
|
@@ -88,4 +93,22 @@ public void contentLength0() throws IOException { |
88 | 93 | } |
89 | 94 | } |
90 | 95 |
|
| 96 | + |
| 97 | + @Test // gh-34971 |
| 98 | + @EnabledForJreRange(min = JRE.JAVA_19) // behavior fixed in Java 19 |
| 99 | + void requestContentLengthHeader() throws Exception { |
| 100 | + URI uri = URI.create(baseUrl + "/header/Content-Length"); |
| 101 | + assertNoContentLength(uri, HttpMethod.GET); |
| 102 | + assertNoContentLength(uri, HttpMethod.DELETE); |
| 103 | + } |
| 104 | + |
| 105 | + protected void assertNoContentLength(URI uri, HttpMethod method) throws Exception { |
| 106 | + ClientHttpRequest request = factory.createRequest(uri, method); |
| 107 | + try (ClientHttpResponse response = request.execute()) { |
| 108 | + assertThat(response.getStatusCode()).as("Invalid response status").isEqualTo(HttpStatus.OK); |
| 109 | + assertThat(StreamUtils.copyToString(response.getBody(), StandardCharsets.ISO_8859_1)) |
| 110 | + .as("Invalid Content-Length request header").isEqualTo("Content-Length:null"); |
| 111 | + } |
| 112 | + } |
| 113 | + |
91 | 114 | } |
0 commit comments