spring-cloud / spring-cloud/spring-cloud-gateway
Forwarding requests to another gateway route is not possible
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
When using a forward:/some/route Route URI where /some/route is matched by another Route's predicate, the request is forwarded by the ForwardRoutingFilter and picked up correctly by the target route.
However, since the ForwardRoutingFilter calls setAlreadyRouted(exchange), the NettyRoutingFilter of the inner filter chain that shares the outer ServerWebExchange will think the request is already routed and therefore won't proxy it.
This might be solved by something like:
if (isAlreadyRouted(exchange) || !"forward".equals(scheme)) {
return chain.filter(exchange);
}
//setAlreadyRouted(exchange); // --- CHANGE: Don't do that yet
//TODO: translate url?
if (log.isTraceEnabled()) {
log.trace("Forwarding to URI: "+requestUrl);
}
return this.dispatcherHandler.getIfAvailable().handle(exchange)
.then(Mono.fromRunnable(() -> setAlreadyRouted(exchange))); // --- CHANGE: Set the flag after the forward before continuing the outer filter chain
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ForwardRoutingFilter and NettyRoutingFilter behavior described in the issue, then reproduce a forward:/some/route request where another route matches the forwarded path. Trace when the shared ServerWebExchange is marked as already routed and verify that the inner chain proxies the request while the outer chain remains correct. Done means forwarding to another gateway route reaches that route successfully without breaking normal routing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100