1.
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
它指定了一个名为 after_route
的路由,将请求转发到 https://example.org
这个 URI。该路由配置了一个断言谓词 After
,它表示只有在请求的时间在指定的时间之后才会匹配该路由。
2.
routes:
- id: before_route
uri: https://example.org
predicates:
- Path=/**
- Before=2017-01-20T17:42:47.789-07:00[America/Denver]
它如果在这个时间之前就访问该uri,否则就访问请求的地址
3.
routes:
- id: between_route
uri: https://example.org
predicates:
- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
跟上面一样,在时间之间就访问uri
4.
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=chocolate, ch.p
当cookie包含chocolate 或者头是ch 就访问uri
5.
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id, \d+
当请求的头部中存在名为 "X-Request-Id" 的头部,并且该头部的值匹配正则表达式 \d+
(表示一个或多个数字字符)时访问uri
6.
routes:
- id: host_route
uri: https://example.org
predicates:
- Host=**.somehost.org,**.anotherhost.org
当请求的主机头(Host header)匹配 **.somehost.org
或 **.anotherhost.org
时访问uri
7.
routes:
- id: method_route
uri: https://example.org
predicates:
- Method=GET,POST
只有当请求的 HTTP 方法为 GET 或 POST 时,才会访问uri
8.
routes:
- id: path_route
uri: https://example.org
predicates:
- Path=/red/{segment},/blue/{segment}
当请求的路径是以 /red/
或 /blue/
开头,并且后面紧跟一个路径段时,访问uri
9.
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=green
当请求的查询参数中包含名为 green
的参数时,访问uri
10.
routes:
- id: remoteaddr_route
uri: https://example.org
predicates:
- RemoteAddr=192.168.1.1/24
当请求的远程地址为 192.168.1.1
或者属于 192.168.1.1
子网的地址时,访问uri
11.
routes:
- id: weight_high
uri: https://weighthigh.org
predicates:
- Weight=group1, 8
- id: weight_low
uri: https://weightlow.org
predicates:
- Weight=group1, 2
如果请求的权重为8,则会路由到 https://weighthigh.org
;如果请求的权重为2,则会路由到 https://weightlow.org
。