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

[Spring Cloud Gateway MVC] Internal forwarded body rewrites umlauts #3537

Open
sapo-di opened this issue Sep 24, 2024 · 0 comments
Open

[Spring Cloud Gateway MVC] Internal forwarded body rewrites umlauts #3537

sapo-di opened this issue Sep 24, 2024 · 0 comments

Comments

@sapo-di
Copy link

sapo-di commented Sep 24, 2024

Describe the bug

I am using spring-cloud-gateway-mvc in an existing application to forward any request starting with a specific route. Some of the requests should be passed to a downstream service and some should be forwarded to a different route in the same service.
If a POST request contains umlauts in the JSON body, forwarding it to the downstream service is fine. If it is forwarded internally the umlauts in the request body are rewritten.

Sample

@Controller
public class MyController {
    private static final Logger logger = LoggerFactory.getLogger(MyController.class);


    private final ObjectMapper objectMapper = new ObjectMapper();


    @RequestMapping(path = "/legacy-route")
    @ResponseBody
    public ResponseEntity<JsonNode> answer(@RequestBody Map<String,String> content) throws JsonProcessingException {
        logger.info(objectMapper.writeValueAsString(content));
        return ResponseEntity.ok(objectMapper.readTree(objectMapper.writeValueAsString(content)));
    }
}
@Controller
public class ProxyController {

    @RequestMapping(path = "/api/{*tail}")
    @ResponseBody
    public void useExchange(@PathVariable("tail") String tail, ProxyExchange<byte[]> exchange) {
        exchange.forward(tail);
    }

}
POST http://localhost:8080/api/legacy-route
Content-Type: application/json
Content-Length: 39
User-Agent: IntelliJ HTTP Client/IntelliJ IDEA 2024.2.1
Accept-Encoding: br, deflate, gzip, x-gzip
Accept: */*

{
  "id" : "unique",
  "umlaut": "ä"
}

###

HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 24 Sep 2024 06:54:55 GMT

{
  "id": "unique",
  "umlaut": "ᅢᄂ"
}
Response file saved.
> 2024-09-24T085455.200.json

Response code: 200; Time: 521ms (521 ms); Content length: 29 bytes (29 B)

I provided an example here: https://github.com/sapo-di/gateway-mvc-test/

Failing test here: https://github.com/sapo-di/gateway-mvc-test/actions/runs/11009568757/job/30569503977

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