GateWay断言
断言Predicate
gateWay网关中提供了多种断言方式
After断言
Loaded RoutePredicateFactory [After]
After
匹配在当前日期时间之后发生的请求
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: after_route uri: https://example.org predicates: - After=2021-09-06T16:02:25.738+08:00[Asia/Shanghai]
|
Before断言
Loaded RoutePredicateFactory [Before]
Before
匹配在当前日期时间之前发生的请求
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: before_route uri: https://example.org predicates: - Before=2021-09-06T16:02:25.738+08:00[Asia/Shanghai]
|
Between断言
Loaded RoutePredicateFactory [Between]
Between
匹配在两个日期之间发生的请求
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: between_route uri: https://example.org predicates: - Between=2021-09-06T16:02:25.738+08:00[Asia/Shanghai], 2021-09-07T16:02:25.738+08:00[Asia/Shanghai]
|
Cookie断言
Loaded RoutePredicateFactory [Cookie]
Cookie
会根据cookie的name以及值的正则表达式进行匹配
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: cookie_route uri: https://example.org predicates: - Cookie=userName, zhangsan
|
Loaded RoutePredicateFactory [Header]
Header是匹配请求头的name以及值的正则表达式进行匹配
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: header_route uri: https://example.org predicates: - Header=X-Request-Id, \d+
|
Host断言
Loaded RoutePredicateFactory [Host]
Host
进行域名匹配,Ant模式匹配
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: host_route uri: https://example.org predicates: - Host=**.somehost.org,**.anotherhost.org
|
Method断言
Loaded RoutePredicateFactory [Method]
Method
匹配HTTP方法
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: method_route uri: https://example.org predicates: - Method=GET,POST
|
Path断言
Loaded RoutePredicateFactory [Path]
Path
进行路径匹配
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: host_route uri: https://example.org predicates: - Path=/foo/{segment},/bar/{segment}
|
Query断言
Loaded RoutePredicateFactory [Query]
Query
查询参数匹配
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: query_route uri: https://example.org predicates: - Query=foo, ba.
|
ReadBodyPredicateFactory断言
Loaded RoutePredicateFactory [ReadBodyPredicateFactory]
RemoteAddr断言
Loaded RoutePredicateFactory [RemoteAddr]
RemoteAddr
远程地址匹配
1 2 3 4 5 6 7 8
| spring: cloud: gateway: routes: - id: remoteaddr_route uri: https://example.org predicates: - RemoteAddr=192.168.1.1/24
|
Weight断言
Loaded RoutePredicateFactory [Weight]
Weight
权重匹配,接收group和weight两个参数,权重是按照组进行计算的
1 2 3 4 5 6 7 8 9 10 11 12
| spring: cloud: gateway: routes: - id: weight_high uri: https://weighthigh.org predicates: - Weight=group1, 8 - id: weight_low uri: https://weightlow.org predicates: - Weight=group1, 2
|
CloudFoundryRouteService断言
Loaded RoutePredicateFactory [CloudFoundryRouteService]