spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

preserve target paths on mvc gateways

Open Interessierter opened this issue 1 year ago • 2 comments

the previous implementation completely removed the path of the configured target which is unexpected and did not match the API (target is given as URI (string) which naturally can contain paths)

I created and attached a small project to reproduce the issue with the current code, see GatewayConfiguration.java:

        return route().GET("/gateway/**", http("http://localhost:8080/finallevel"))
                .before(stripPrefix(1))
                .build();

So when calling http://localhost:8080/gateway/hello it is expected to see the content from http://localhost:8080/finallevel/hello but instead the content of http://localhost:8080/hello only is displayed.

Of course this example is contrieved and that case can here simply be circumvented by adding a before(prefixPath("finallevel")) to the route builder but my usecase is to determine the target dynamically (which is advertised in the documentation and a really useful feature), some targets have a path, some dont

gateway-pathsgone.zip

Interessierter avatar Feb 09 '24 09:02 Interessierter

@Interessierter Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-cla avatar Feb 09 '24 09:02 pivotal-cla

@Interessierter Thank you for signing the Contributor License Agreement!

pivotal-cla avatar Feb 09 '24 09:02 pivotal-cla

This is the existing behaviour of the reactive gateway. Any changes to the path should be made by a filter.

spencergibb avatar Mar 08 '24 15:03 spencergibb

@spencergibb that's a real pity because as I wrote the API suggests that you can use "real" URIs as target where you can in fact just use server addresses without any paths - IMHO the documentation should be updated to reflect this fact, this will save new developers lots of time - maybe a hint here: https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/java-routes-api.html#gateway-handlerfunctions would be good.

and FYI in https://github.com/spring-cloud/spring-cloud-gateway/pull/3162 another user is complaining about exactly the same "feature"

Interessierter avatar Mar 11 '24 13:03 Interessierter

@Interessierter see #3292 for the documentation issue. You've convinced me that the feature would be welcome. I've opened #3293 to track it as I see how it should work.

spencergibb avatar Mar 11 '24 15:03 spencergibb