MockHttpServletRequestBuilder reliably detects form body content type again

Issue: SPR-15116
This commit is contained in:
Juergen Hoeller 2017-01-16 11:49:07 +01:00
parent bb9e561934
commit e88e8f1d09
1 changed files with 8 additions and 4 deletions

View File

@ -70,6 +70,7 @@ import org.springframework.web.util.UriUtils;
* {@code MockHttpServletRequest} can be plugged in via {@link #with(RequestPostProcessor)}.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Arjen Poutsma
* @author Sam Brannen
* @author Kamill Sokol
@ -630,10 +631,13 @@ public class MockHttpServletRequestBuilder
}
}
if (this.content != null && this.contentType != null) {
MediaType mediaType = MediaType.parseMediaType(this.contentType);
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
addRequestParams(request, parseFormData(mediaType));
if (this.content != null && this.content.length > 0) {
String requestContentType = request.getContentType();
if (requestContentType != null) {
MediaType mediaType = MediaType.parseMediaType(requestContentType);
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
addRequestParams(request, parseFormData(mediaType));
}
}
}