Browse Source

MockHttpServletRequestBuilder reliably detects form body content type again

Issue: SPR-15116
pull/1296/merge
Juergen Hoeller 9 years ago
parent
commit
e88e8f1d09
  1. 12
      spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

12
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

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

Loading…
Cancel
Save