zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    HDU 1290 献给杭电五十周年校庆的礼物(面分割空间 求得到的最大空间数目)
    2018年暑假ACM个人训练题6 解题报告
    HDU 2096 小明A+B(%的运用)
    HDU 2097 sky数 (进制转化)
    布局(codevs 1242)
    Remmarguts’ Date(poj 2449)
    魔法猪学院(codevs 1835)
    统计单词个数(codevs 1040)
    小L 的二叉树(洛谷 U4727)
    Shortest Prefixes(poj 2001)
  • 原文地址:https://www.cnblogs.com/jwdd/p/15603912.html
Copyright © 2011-2022 走看看