SetPath 网关过滤器工厂

SetPath 网关过滤器工厂接受一个路径 template 参数。它提供了一种简单的方式,通过允许路径中的模板化段来操作请求路径。这使用了 Spring Framework 中的 URI 模板。允许多个匹配段。以下示例配置了一个 SetPath 网关过滤器

application.yml
spring:
  cloud:
    gateway:
      routes:
      - id: setpath_route
        uri: https://example.org
        predicates:
        - Path=/red/{segment}
        filters:
        - SetPath=/{segment}

对于 /red/blue 的请求路径,这会在发起下游请求之前将路径设置为 /blue