Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tschut opened this issue May 14, 2024 · 0 comments
Open

Comments

@tschut
Copy link

tschut commented May 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant