spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Can't have @PostRequest with formdata in spring-cloud-gateway-mvc application

Open tschut opened this issue 1 year ago • 1 comments
trafficstars

Describe the bug I'm on spring-cloud-gateway-server-mvc version 4.1.2.

In my application I have a simple controller:

@RestController
@RequestMapping("/internal/test")
class TestController {
    @PostMapping
    fun test(@RequestBody(required = false) body: String?) {
        println("####### body: $body")
    }
}

I then use curl to call this endpoint (note curl will add Content-Type: application/x-www-form-urlencoded):

curl "http://localhost:8080/internal/test" -d "foo=bar"

and the output is

####### body: null

When I add the property spring.cloud.gateway.mvc.form-filter.enabled: false it works again and the output is as expected.

Is having a @PostMapping with form data supposed to work in an application with spring-cloud-gateway? I found this in the docs https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/working-with-servlets-and-filters.html#page-title, but it's not clear to me how this would apply to a Controller and not a Filter.

When debugging I found that at this point, request.getParameterMap() returns an empty map instead of a map with 1 entry (as it does when the form filter is disabled). Note that at this point, request is the request as it was wrapped by FormFilter.

tschut avatar May 14 '24 08:05 tschut

I experience the same problem.

Here is a minimalist repository showing the problem:

https://github.com/mindhaq/spring-gateway-mvc-formfilter-bugreport

mindhaq avatar Jun 22 '24 20:06 mindhaq