springcloud-Finchley学习笔记-gateway路由匹配配置

路由匹配

  • After路由匹配:匹配指定时间之后的请求
spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: http://example.org
        predicates:
        - After=2017-01-20T17:42:47.789-07:00[America/Denver]
  • Before路由匹配:匹配指定时间之前的请求
spring:
  cloud:
    gateway:
      routes:
      - id: before_route
        uri: http://example.org
        predicates:
        - Before=2017-01-20T17:42:47.789-07:00[America/Denver]
  • Between路由匹配:匹配指定时间区间的请求
spring:
  cloud:
    gateway:
      routes:
      - id: between_route
        uri: http://example.org
        predicates:
        - Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
  • Cookie路由匹配:匹配指定Cookie的值匹配设定正则表达式的请求
spring:
  cloud:
    gateway:
      routes:
      - id: cookie_route
        uri: http://example.org
        predicates:
        - Cookie=chocolate, ch.p #匹配cookie名为chocolate的值为ch.p的请求
  • Header路由匹配:匹配指定header的值匹配设定正则表达式的请求
spring:
 cloud:
   gateway:
     routes:
     - id: header_route
       uri: http://example.org
       predicates:
       - Header=X-Request-Id, \d+  #匹配头信息X-Request-Id的值匹配\d+的正则表达式
  • Host路由匹配:Host匹配设定的表达式
spring:
  cloud:
    gateway:
      routes:
      - id: host_route
        uri: http://example.org
        predicates:
        - Host=**.somehost.org
  • Method路由匹配:匹配HttpMethod方法为设定值的请求
spring:
  cloud:
    gateway:
      routes:
      - id: method_route
        uri: http://example.org
        predicates:
        - Method=GET
  • Path路由匹配:请求路径匹配设定表达式(a Spring PathMatcher pattern)的请求
spring:
  cloud:
    gateway:
      routes:
      - id: host_route
        uri: http://example.org
        predicates:
        - Path=/foo/{segment}   #请求路径匹配路径匹配表达式/foo/{segment}
  • Query路由匹配:请求参数匹配设定值 或表达式的请求
spring:
  cloud:
    gateway:
      routes:
      - id: query_route
        uri: http://example.org
        predicates:
        - Query=baz #请求参数中包含baz参数

你可能感兴趣的:(SpringCloud,springboot)