16
16
17
17
package org .springframework .http .client ;
18
18
19
+ import java .io .InputStreamReader ;
19
20
import java .net .URI ;
20
21
import java .nio .charset .StandardCharsets ;
21
22
import java .util .Arrays ;
@@ -49,12 +50,7 @@ void repeatableRead() throws Exception {
49
50
FileCopyUtils .copy (body , request .getBody ());
50
51
try (ClientHttpResponse response = request .execute ()) {
51
52
assertThat (response .getStatusCode ()).as ("Invalid status code" ).isEqualTo (HttpStatus .OK );
52
- assertThat (response .getStatusCode ()).as ("Invalid status code" ).isEqualTo (HttpStatus .OK );
53
-
54
- assertThat (response .getHeaders ().containsKey (headerName )).as ("Header not found" ).isTrue ();
55
53
assertThat (response .getHeaders ().containsKey (headerName )).as ("Header not found" ).isTrue ();
56
-
57
- assertThat (response .getHeaders ().get (headerName )).as ("Header value not found" ).isEqualTo (Arrays .asList (headerValue1 , headerValue2 ));
58
54
assertThat (response .getHeaders ().get (headerName )).as ("Header value not found" ).isEqualTo (Arrays .asList (headerValue1 , headerValue2 ));
59
55
60
56
byte [] result = FileCopyUtils .copyToByteArray (response .getBody ());
@@ -64,4 +60,14 @@ void repeatableRead() throws Exception {
64
60
}
65
61
}
66
62
63
+ @ Test
64
+ void shouldNotSetContentLengthWhenEmptyBody () throws Exception {
65
+ ClientHttpRequest request = factory .createRequest (URI .create (baseUrl + "/header/Content-Length" ), HttpMethod .POST );
66
+ try (ClientHttpResponse response = request .execute ()) {
67
+ assertThat (response .getStatusCode ()).as ("Invalid status code" ).isEqualTo (HttpStatus .OK );
68
+ String result = FileCopyUtils .copyToString (new InputStreamReader (response .getBody ()));
69
+ assertThat (result ).as ("Invalid body" ).isEqualTo ("Content-Length:null" );
70
+ }
71
+ }
72
+
67
73
}
0 commit comments