Skip to content

Commit cce8471

Browse files
committed
MockHttpServletRequestBuilder reliably detects form body content type again
Issue: SPR-15116 (cherry picked from commit e88e8f1)
1 parent 7f12730 commit cce8471

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* {@code MockHttpServletRequest} can be plugged in via {@link #with(RequestPostProcessor)}.
7171
*
7272
* @author Rossen Stoyanchev
73+
* @author Juergen Hoeller
7374
* @author Arjen Poutsma
7475
* @author Sam Brannen
7576
* @author Kamill Sokol
@@ -633,10 +634,13 @@ public final MockHttpServletRequest buildRequest(ServletContext servletContext)
633634
}
634635
}
635636

636-
if (this.content != null && this.contentType != null) {
637-
MediaType mediaType = MediaType.parseMediaType(this.contentType);
638-
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
639-
addRequestParams(request, parseFormData(mediaType));
637+
if (this.content != null && this.content.length > 0) {
638+
String requestContentType = request.getContentType();
639+
if (requestContentType != null) {
640+
MediaType mediaType = MediaType.parseMediaType(requestContentType);
641+
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
642+
addRequestParams(request, parseFormData(mediaType));
643+
}
640644
}
641645
}
642646

0 commit comments

Comments
 (0)