Skip to content

Commit

Permalink
MockHttpServletRequestBuilder sets content-length
Browse files Browse the repository at this point in the history
Closes gh-23978
  • Loading branch information
rstoyanchev committed Nov 12, 2019
1 parent 4bbf2d5 commit f4c847b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Expand Up @@ -687,6 +687,13 @@ public final MockHttpServletRequest buildRequest(ServletContext servletContext)
}
});

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();
Expand Down
Expand Up @@ -389,6 +389,7 @@ public void body() throws IOException {
byte[] result = FileCopyUtils.copyToByteArray(request.getInputStream());

assertThat(result).isEqualTo(body);
assertThat(request.getContentLength()).isEqualTo(body.length);
}

@Test
Expand Down

0 comments on commit f4c847b

Please sign in to comment.