首页 > 其他分享 >spring cloud gateway-filter深入了解(StripPrefix与PrefixPath)

spring cloud gateway-filter深入了解(StripPrefix与PrefixPath)

时间:2022-08-17 11:13:42浏览次数:91  
标签:lbs StripPrefix service spring filter bds gateway

网关过滤器

StripPrefix 过滤器

  • 作用: 去掉部分URL路径

 

spring:
  cloud:
    gateway:
      routes:
      - id: bds-lbs-service
        uri: lb://bds-lbs-service
        predicates:
        - Path=/lbs/**
        filters:
        - StripPrefix=1
  • 如上,我们访问网关地址http://host:port/lbs/hello
    • 若无StripPrefix过滤器时,gateway 发送请求到后台服务bds-lbs-service的url就是http://bds-lbs-service/lbs/hello
    • 若有StripPrefix过滤器时,gateway会根据StripPrefix=1所配的值(这里是1)去掉URL路径中的部分前缀(这里去掉一个前缀,即去掉lbs
      • 发送请求到后台服务spring-cloud-producer的url变成http://bds-lbs-service/hello

 

PrefixPath 过滤器

  • 作用: 它的作用和StripPrefix正相反,是在URL路径前面添加一部分的前缀

  

spring:
  cloud:
    gateway:
      routes:
      - id: bds-lbs-service
        uri: lb://bds-lbs-service
        filters:
        - PrefixPath=/lbs

  

  • 这将会把/lbs添加到路由prefixpath_route匹配到的所有请求的路径的前面。
    • 所以对/hello的请求将会被发送到/lbs/hello

  

 

转:spring cloud gateway-filter深入了解(StripPrefix与PrefixPath)

标签:lbs,StripPrefix,service,spring,filter,bds,gateway
From: https://www.cnblogs.com/nextgg/p/16594348.html

相关文章