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

Forwarding requests to another gateway route is not possible

Open
#787 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.