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

ModifyResponseGatewayFilter is not using newContentType from Config #2647

Closed
muchnik opened this issue Jun 22, 2022 · 1 comment · Fixed by #2649
Closed

ModifyResponseGatewayFilter is not using newContentType from Config #2647

muchnik opened this issue Jun 22, 2022 · 1 comment · Fixed by #2649

Comments

@muchnik
Copy link
Contributor

muchnik commented Jun 22, 2022

Problem:
I wanted to modify response body with changing Content-type, but probably SCG ignoring newContentType
ModifyResponseGatewayFilter is not using newContentType in code as expected to set response 'Content-Type' header.

Don't see any usage of newContentType here:
https://github.com/spring-cloud/spring-cloud-gateway/blob/main/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java#L91

SCG version 3.1.2

Example:

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                      .route("r1", r ->
                              r.path("/megatest")
                               .filters(gatewayFilterSpec -> {
                                   return gatewayFilterSpec
                                           .modifyResponseBody(c -> c
                                                   .setInClass(String.class)
                                                   .setOutClass(String.class)
                                                   .setNewContentType(MediaType.TEXT_PLAIN_VALUE)
                                                   .setRewriteFunction((exchange, o) -> Mono.just(((String) o).toUpperCase())))
                                           .setPath("/target");
                               })
                               .uri("http://localhost:9999"))
                      .build();
    }

Current behaviour:
Response content-type is set from actual target response from external system.
I'am not getting 'text/plain' as expected

Expected behaviour:
Response content-type is set from newContentType field and equals 'text/plain'.

Further:
I can manage to fix this problem after discussion.

muchnik added a commit to muchnik/spring-cloud-gateway that referenced this issue Jun 22, 2022
…ontent-type, if newContentType is present in config. Fixes spring-cloudgh-2647
@spencergibb
Copy link
Member

closing in favor of #2649

spencergibb pushed a commit that referenced this issue Mar 8, 2024
…ontent-type, if newContentType is present in config. Fixes gh-2647 (#2649)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants