提交 f4c847b7 编写于 作者: R Rossen Stoyanchev

MockHttpServletRequestBuilder sets content-length

Closes gh-23978
上级 4bbf2d57
......@@ -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();
......
......@@ -389,6 +389,7 @@ public class MockHttpServletRequestBuilderTests {
byte[] result = FileCopyUtils.copyToByteArray(request.getInputStream());
assertThat(result).isEqualTo(body);
assertThat(request.getContentLength()).isEqualTo(body.length);
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册