MockHttpServletRequestBuilder reliably detects form body content type again
Issue: SPR-15116
This commit is contained in:
parent
bb9e561934
commit
e88e8f1d09
|
@ -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,12 +631,15 @@ 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 (requestContentType != null) {
|
||||||
|
MediaType mediaType = MediaType.parseMediaType(requestContentType);
|
||||||
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
|
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
|
||||||
addRequestParams(request, parseFormData(mediaType));
|
addRequestParams(request, parseFormData(mediaType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!ObjectUtils.isEmpty(this.cookies)) {
|
if (!ObjectUtils.isEmpty(this.cookies)) {
|
||||||
request.setCookies(this.cookies.toArray(new Cookie[this.cookies.size()]));
|
request.setCookies(this.cookies.toArray(new Cookie[this.cookies.size()]));
|
||||||
|
|
Loading…
Reference in New Issue