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

multipart body request is empty when using BeforeFilterFunctions rewritePath #3663

Open
RomainPro76 opened this issue Jan 9, 2025 · 0 comments

Comments

@RomainPro76
Copy link

Describe the bug
I'm using spring gateway mvc as a simple gateway to route input request to backend app. My route config rewrite the host and the url base path.
It works well except for multipart requests. With a multipart request, the output body is empty.
After some research in my side to identify the problem, it seems the rewritePath function is the root cause. If I delete it of my route, multipart requests works.
I'm using the function rewritePath in org.springframework.cloud.gatexay.server.mvc.BeforeFilterFunctions in a RouterFunction policy.

Sample

To prove the problem, I reproduced the case with this simple code.

@Configuration
public class RouterConfiguration {
    private static final String WILDCARD = "/**";
    private static final String SEGMENT_TO_INCLUDE_REGEX = "(?<segment>.*)";
    private static final String SEGMENT_TO_ADD_REGEX = "${segment}";
    
    @Bean
    public RouterFunctions.Builder routerFunctionsBuilder() {
        return RouterFunctions.route();
    }

    @Bean
    public RouterFunction<ServerResponse> buildRoutes(RouterFunctions.Builder routerFunctionsBuilder) {
        var destinationHost = URI.create("http://localhost:9008/");
        
        routerFunctionsBuilder
                .POST("multipart" + WILDCARD, HandlerFunctions.http(destinationHost)) // multipart works with this line only
                // multipart don't work anymore in adding the filter (body is empty)
                .before(BeforeFilterFunctions.rewritePath("multipart" + SEGMENT_TO_INCLUDE_REGEX, "/api/multipart" + SEGMENT_TO_ADD_REGEX));

        return routerFunctionsBuilder.build();
    }

}

Versions
Spring Boot : 3.3.0
spring cloud starter gateway mvc : 4.1.5

related issues but not solved : 3449

** Expectations **
rewritePath function works with multipart requests

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