SpringCloudGateway内置GatewayFilter工厂类之Path类过滤器 (三)

1:PrefixPath

  将所有请求路径前加上路径;value

- PrefixPath=value
spring:
  cloud:
    gateway:
      routes:
      - id: prefixpath_route
        uri: http://example.org
        filters:
        - PrefixPath=value

2:RewritePath

  利用路径正则表达式灵活替换请求路径

  eg:

spring:
    cloud:
        gateway:
            routes:
            #插件请求转发 
            #(?<segment>/?.*):匹配 /任意字符,此处/出现0次或1次。将匹配到的结果捕获到名称为segment的组中
            #$\{segment}:将 segment所捕获到的文本置换到此处,注意,\的出现是由于避免yaml认为这是一个变量,在gateway进行解析时,会被替换为${segment}
            - id: "ms-api-gateway"
              uri: "lb://ms-api-gateway"
              predicates:
              - Path=/isv/mini/common/**
              filters:
              - RewritePath=/isv(?<segment>/?.*), /isv/ms/app$\{segment}

3:SetPath

  SetPath GatewayFilter Factory采用路径模板参数。 它提供了一种通过允许模板化路径段来操作请求路径的简单方法。 这使用了Spring Framework中的uri模板。 允许多个匹配的段。

- SetPath=/{segment}

  eg:

spring:
  cloud:
    gateway:
      routes:
      - id: setpath_route
        uri: http://example.org
        predicates:
        - Path=/foo/{segment}
        filters:
        - SetPath=/{segment}

4:StripPrefix

   StripPrefix网关过滤器工厂采用一个参数StripPrefix。 StripPrefix参数表示在将请求发送到下游之前从请求中剥离的路径个数。

- StripPrefix

  eg:

spring:
  cloud:
    gateway:
      routes:
      - id: nameRoot
        uri: http://nameservice
        predicates:
        - Path=/name/**
        filters:
        - StripPrefix=1
原文地址:https://www.cnblogs.com/jwdd/p/15603912.html