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: * https://github.com/spring-projects/spring-framework/blob/279f9647ab4e3b2f875ab397a911d34edfbf3dce/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilder.java#L81 * https://github.com/spring-projects/spring-framework/blob/279f9647ab4e3b2f875ab397a911d34edfbf3dce/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java#L157

Comment From: rstoyanchev

Indeed, it looks like MockMvc doesn't have methods in MockMvcRequestBuilders to create a multipart request with an HTTP method other than POST, so hardcoded.

Comment From: kewne

Apologies for the potential spam but really wanted to leave my thanks for taking care of this, keep up the good work! 👍