spring-cloud/spring-cloud-gateway
Support paths on Route URIs as syntactic sugar for the `SetPath` filter
开放
#3,293 创建于 2024年3月11日
enhancementhelp wanted
仓库指标
- 星标
- (4,284 个星标)
- PR 合并指标
- (PR 指标待抓取)
描述
There have been multiple requests and feedback regarding the ignoring of paths on Route URIs. Part of my hesitancy is how to support it across ALL means of configuring routes both reactive and MVC: config props, Java DSL and actuator.
I'm comfortable proposing it as syntactic sugar for the SetPath filter. There would be a mechanism to remove the path from the URI and insert a SetPath filter with that URI. There would be NO customization, at that point, break out to the original SetPath configuration.
The two routes in each of the following examples would be equivalent:
spring:
cloud:
gateway:
routes:
- id: set_path
uri: http://example.com
predicates:
- Path=/foo/{segment}
filters:
- SetPath=/{segment}
- id: set_path_uri
uri: http://example.com/{segment}
predicates:
- Path=/foo/{segment}
reactive Java DSL
@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route("setpath", p -> p.path("/foo/{segment}")
.filters(f -> f.setPath("/{segment}"))
.uri("http://example.com"))
.route("setpathuri", p -> p.path("/foo/{segment}")
.uri("http://example.com/{segment}"))
.build();
}
MVC Java DSL
@Bean
public RouterFunction<ServerResponse> setPathRoute() {
return route("setpath")
.route(path("/foo/{segment}"), http("http://example.com"))
.before(setPath("/{segment}"))
.build().and(route()
.route(path("/foo/{segment}"), http("http://example.com/{segment}"))
.build());
}
/cc @joshlong