MockHttpServletRequestBuilder sets content-length

Closes gh-23978
This commit is contained in:
Rossen Stoyanchev 2019-11-12 17:32:40 +00:00
parent 4bbf2d5785
commit f4c847b723
2 changed files with 8 additions and 0 deletions

View File

@ -687,6 +687,13 @@ public class MockHttpServletRequestBuilder
}
});
if (!ObjectUtils.isEmpty(this.content) &&
!this.headers.containsKey(HttpHeaders.CONTENT_LENGTH) &&
!this.headers.containsKey(HttpHeaders.TRANSFER_ENCODING)) {
request.addHeader(HttpHeaders.CONTENT_LENGTH, this.content.length);
}
String query = this.url.getRawQuery();
if (!this.queryParams.isEmpty()) {
String s = UriComponentsBuilder.newInstance().queryParams(this.queryParams).build().encode().getQuery();

View File

@ -389,6 +389,7 @@ public class MockHttpServletRequestBuilderTests {
byte[] result = FileCopyUtils.copyToByteArray(request.getInputStream());
assertThat(result).isEqualTo(body);
assertThat(request.getContentLength()).isEqualTo(body.length);
}
@Test