GateWay断言
断言Predicate
gateWay网关中提供了多种断言方式
After断言
Loaded RoutePredicateFactory [After]
After
匹配在当前日期时间之后发生的请求
1 | spring: |
Before断言
Loaded RoutePredicateFactory [Before]
Before
匹配在当前日期时间之前发生的请求
1 | spring: |
Between断言
Loaded RoutePredicateFactory [Between]
Between
匹配在两个日期之间发生的请求
1 | spring: |
Cookie断言
Loaded RoutePredicateFactory [Cookie]
Cookie
会根据cookie的name以及值的正则表达式进行匹配
1 | spring: |
Header断言
Loaded RoutePredicateFactory [Header]
Header是匹配请求头的name以及值的正则表达式进行匹配
1 | spring: |
Host断言
Loaded RoutePredicateFactory [Host]
Host
进行域名匹配,Ant模式匹配
1 | spring: |
Method断言
Loaded RoutePredicateFactory [Method]
Method
匹配HTTP方法
1 | spring: |
Path断言
Loaded RoutePredicateFactory [Path]
Path
进行路径匹配
1 | spring: |
Query断言
Loaded RoutePredicateFactory [Query]
Query
查询参数匹配
1 | spring: |
ReadBodyPredicateFactory断言
Loaded RoutePredicateFactory [ReadBodyPredicateFactory]
RemoteAddr断言
Loaded RoutePredicateFactory [RemoteAddr]
RemoteAddr
远程地址匹配
1 | spring: |
Weight断言
Loaded RoutePredicateFactory [Weight]
Weight
权重匹配,接收group和weight两个参数,权重是按照组进行计算的
1 | spring: |
CloudFoundryRouteService断言
Loaded RoutePredicateFactory [CloudFoundryRouteService]
配置方式
gateway配置断言有两种方式
以Cookie断言为例,Cookie断言的配置类如下
1 | public static class Config { |
简短配置
断言名称和参数之间是
=
,多个参数之间,
相隔,按照定义的顺序依次赋值1
2
3
4
5
6
7
8spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- Cookie=mycookie,mycookievalue
全面扩展参数
每个参数都使用
字段名:字段值
表示1
2
3
4
5
6
7
8
9
10
11spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- name: Cookie
args:
name: mycookie
regexp: mycookievalue