SetPath GatewayFilter 工廠

SetPath GatewayFilter 工廠採用路徑 template 參數。它提供一個簡單的方式來操作請求路徑,允許路徑的範本化區段。這使用來自 Spring Framework 的 URI 範本。允許多個匹配的區段。以下範例設定了 SetPath GatewayFilter

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

對於 /red/blue 的請求路徑,這會在發出下游請求之前將路徑設定為 /blue