spring-cloud / spring-cloud/spring-cloud-gateway

[Spring Cloud Gateway MVC] Internal forwarded body rewrites umlauts

Open
#3,537 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ProxyController and its ProxyExchange<byte[]> call shown in the report, then reproduce the request using the linked gateway-mvc-test example or failing test run. Trace the internal forwarding path and verify that a POST body containing "ä" remains unchanged in the downstream response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.