Closed
Description
Affects: latest (6.0.0, 5.3.20)
When making a multipart/form-data
request using WebTestClient
, the HTTP method of the request is overwritten to POST
:
For example, the following test:
@Test
void returns_no_content_on_success() {
var builder = new MultipartBodyBuilder();
builder.part("file", TestResources.JPEG_IMAGE, MediaType.IMAGE_JPEG);
webTestClient.put()
.uri("/test")
.bodyValue(builder.build())
.exchange()
.expectStatus().isNoContent();
}
generates the following log output:
> PUT /test
> WebTestClient-Request-Id: [1]
> Content-Type: [multipart/form-data;boundary=1TV9nXkH1G9MW2IM7_NyhWx2AJYVwdNGd]
159180 bytes of content.
< 405 METHOD_NOT_ALLOWED Method Not Allowed
< Allow: [PUT,DELETE]
< Content-Type: [application/problem+json]
156 bytes of content.
====================== MockMvc (Server) ===============================
MockHttpServletRequest:
HTTP Method = POST
Request URI = /test
Parameters = {}
Headers = [Content-Type:"multipart/form-data;charset=UTF-8", WebTestClient-Request-Id:"1"]
Body = null
I've traced this to a some code that implies that Multipart requests are always POST
: