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