• Spring Cloud Gateway(八):其它路由谓词工厂


    本文基于 spring cloud gateway 2.0.1

    6、基于Cookie的谓词工厂

    CookieRoutePredicateFactory 是 Cookie 类型的路由断言工厂,接收两个参数: cookie 名字和一个正则表达式。 此谓词匹配具有给定名称且值与正则表达式匹配的cookie。

    spring:
      cloud:
        gateway:
          routes:
          - id: cookie_route
            uri: http://example.org
            predicates:
            - Cookie=chocolate, ch.p
    

    此路由匹配请求有一个名为chocolate的cookie,其值与ch.p正则表达式匹配。

    7、基于Header的谓词工厂

    Header Route Predicate Factory有两个参数,标题名称和正则表达式。此谓词与具有给定名称且值与正则表达式匹配的标头匹配。

    spring:
      cloud:
        gateway:
          routes:
          - id: header_route
            uri: http://example.org
            predicates:
            - Header=X-Request-Id, d+
    

    如果请求具有名为X-Request-Id的标头,则该路由匹配,其值与 d +正则表达式匹配(具有一个或多个数字的值)。

    8、基于Host的谓词工厂

    Host Route Predicate Factory采用一个参数:主机名模式。该模式是一种Ant样式模式“.”作为分隔符。此谓词匹配与模式匹配的Host标头。

    spring:
      cloud:
        gateway:
          routes:
          - id: host_route
            uri: http://www.baidu.com
            predicates:
            - Host=**.testhost.org
    

    如果请求的主机头具有值 **.testhost.org,则此路由将匹配。

    9、基于Method请求方法的谓词工厂

    Method Route Predicate Factory采用一个参数:要匹配的HTTP方法。

    spring:
      cloud:
        gateway:
          routes:
          - id: method_route
            uri: http://example.org
            predicates:
            - Method=GET
    

    如果请求的 Method 为 GET,则匹配该路由。

    10、基于Path请求路径的谓词工厂

    PathRoutePredicateFactory 是基于请求路径的路由断言工厂,接收一个参数: Spring 的 PathMatcher 模式串。

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

    如果请求路径是 /foo/1 或者/foo/bar,将会匹配该路由。

    11、基于Query请求参数的路由工厂

    QueryRoutePredicateFactory 是请求参数的路由断言工厂,接收两个参数: 一个 必须的请求param 和一个可选的正则表达式。

    spring:
      cloud:
        gateway:
          routes:
          - id: query_route
            uri: http://example.org
            predicates:
            - Query=baz, ba.
    

    如果请求中包含baz查询参数,且其值匹配 ba. 正则表达式,将会匹配该路由。

  • 相关阅读:
    [Win32]一个调试器的实现(十)显示变量
    [Win32]防止套接字被继承
    [C++]实现委托模型
    [Win32]一个调试器的实现(十一)显示函数调用栈
    [Win32]IP数据报的首部如何定义
    FMECA方法及工程应用
    C#控制台应用程序自动关闭
    ckedit 3.0 配置(一)
    [转]“余则成”教你办公室生存法则20条
    Element UI之Select选择器优化
  • 原文地址:https://www.cnblogs.com/liukaifeng/p/10055865.html
Copyright © 2020-2023  润新知