For lb: scheme, put associated filters last.

This makes sure the lb filter runs after path modifying filters like stripPrefix.

See gh-3443
This commit is contained in:
spencergibb
2025-03-17 16:12:09 -04:00
parent b82da55fae
commit f6f90df404
8 changed files with 21 additions and 5 deletions

View File

@@ -43,6 +43,8 @@ spring:
- Path=/api/**
----
WARNING: If using the `lb()` filter, it needs to be after any filter that manipulates the path such as `setPath()` or `stripPrefix()`, otherwise the resulting url could be incorrect. The `lb:` scheme handler in configuration, automatically puts the filter in the highest precedence order.
NOTE: By default, when a service instance cannot be found by the `ReactorLoadBalancer`, a `503` is returned.
// TODO: implement use404
// You can configure the gateway to return a `404` by setting `spring.cloud.gateway.loadbalancer.use404=true`.

View File

@@ -33,7 +33,7 @@ class RouteConfiguration {
public RouterFunction<ServerResponse> gatewayRouterFunctionsPrefixPath() {
return route("prefixpath_route")
.GET("/**", http("https://example.org"))
.before("/mypath")
.before(prefixPath("/mypath"))
.build();
}
}
@@ -42,3 +42,4 @@ class RouteConfiguration {
This prefixes `/mypath` to the path of all matching requests.
So a request to `/hello` is sent to `/mypath/hello`.
WARNING: If using the `lb()` filter, it needs to be after the `prefixPath()` filter, otherwise the resulting url could be incorrect. The `lb:` scheme handler in configuration, automatically puts the filter in the highest precedence order.

View File

@@ -43,3 +43,4 @@ class RouteConfiguration {
For a request path of `/red/blue`, this sets the path to `/blue` before making the downstream request. Note that in `application.yml` the `$` should be replaced with `$\` because of the YAML specification.
WARNING: If using the `lb()` filter, it needs to be after the `rewritePath()` filter, otherwise the resulting url could be incorrect. The `lb:` scheme handler in configuration, automatically puts the filter in the highest precedence order.

View File

@@ -45,3 +45,4 @@ class RouteConfiguration {
For a request path of `/red/blue`, this sets the path to `/blue` before making the downstream request.
WARNING: If using the `lb()` filter, it needs to be after the `setPath()` filter, otherwise the resulting url could be incorrect. The `lb:` scheme handler in configuration, automatically puts the filter in the highest precedence order.

View File

@@ -43,3 +43,4 @@ class RouteConfiguration {
When a request is made through the gateway to `/name/blue/red`, the request made to `nameservice` looks like `https://nameservice/red`.
WARNING: If using the `lb()` filter, it needs to be after the `stripPrefix()` filter, otherwise the resulting url could be incorrect. The `lb:` scheme handler in configuration, automatically puts the filter in the highest precedence order.