Skip to content

Return 415 for form data via @RequestBody in WebFlux #26386

@huberchrigu

Description

@huberchrigu

A @RestController like

@RestController
 public class DemoController {
     @PostMapping
     public Map<String, Object> getAttributes(@RequestBody Body body, ServerWebExchange serverWebExchange) {
         return serverWebExchange.getAttribute(body.getAttribute());
     }
 }

is expected to handle requests with content type application/json. When the client request has a content type x-www-form-urlencoded, I would expect that the server returns 415 Unsupported Media Type or another client error.
Instead Spring throws java.lang.IllegalStateException: In a WebFlux application, form data is accessed via ServerWebExchange.getFormData().

A sample application with failing test can be found here: https://github.com/huberchrigu/spring-reactive-wrong-content-type

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions