Describe the bug
In Spring Cloud Gateway MVC 4.2.1 (included via spring-cloud-dependencies 2024.0.1) routing is broken with the StripPrefix filter.
The original URI comes in to the gateway as http://localhost:8080/foo/bar/baz. Route config:
server:
port: 8000
spring:
cloud:
gateway:
mvc:
routes:
- id: bar
uri: http://localhost:9000
predicates:
- Path=/foo/bar/**
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
- TokenRelay=
- StripPrefix=2
Final URL to forward to should be http://localhost:9000/baz.
This works with Gateway MVC 4.2.0. It fails with 4.2.1, which tries to connect to http://localhost:8080/baz.
Analysis
This is a recurrence of #3055 and #3178, only this time for all the functions in which commits b8200a3 and b82da55 added these MvcUtils.setRequestUrl() calls. For instance in stripPrefix at
|
MvcUtils.setRequestUrl(request, prefixedUri); |
This overwrites the configured route URI, and in the end the forward goes to the wrong server.
Describe the bug
In Spring Cloud Gateway MVC 4.2.1 (included via spring-cloud-dependencies 2024.0.1) routing is broken with the StripPrefix filter.
The original URI comes in to the gateway as
http://localhost:8080/foo/bar/baz. Route config:Final URL to forward to should be
http://localhost:9000/baz.This works with Gateway MVC 4.2.0. It fails with 4.2.1, which tries to connect to
http://localhost:8080/baz.Analysis
This is a recurrence of #3055 and #3178, only this time for all the functions in which commits b8200a3 and b82da55 added these
MvcUtils.setRequestUrl()calls. For instance in stripPrefix atspring-cloud-gateway/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/BeforeFilterFunctions.java
Line 443 in 8553c04
This overwrites the configured route URI, and in the end the forward goes to the wrong server.