1、 After Route Predicate Factory
输入一个参数:时间,匹配该时间之后的请求,示例配置:
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://nowjava.com
predicates:
- After=2019-11-11T11:11:11.111+08:00[Asia/Shanghai]
2、Before Route Predicate Factory
输入一个参数:时间,匹配该时间之前的请求,示例配置:
spring:
cloud:
gateway:
routes:
- id: before_route
uri: https://nowjava.com
predicates:
- Before=2019-11-11T11:11:11.111+08:00[Asia/Shanghai]
3、Between Route Predicate Factory
输入两个参数:时间1、时间2,匹配该时间段的请求,示例配置:
spring:
cloud:
gateway:
routes:
- id: between_route
uri: https://nowjava.com
predicates:
- Between=2019-11-10T11:11:11.111+08:00[Asia/Shanghai], 2019-11-12T11:11:11.111+08:00[Asia/Shanghai]
4、Cookie Route Predicate Factory
输入两个参数:Cookie 名称、正则表达式,匹配 Cookie 中是否存在该名称且值与正则表达式匹配,示例配置:
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://nowjava.com
predicates:
- Cookie=name, ano.i
5、Header Route Predicate Factory
输入两个参数:Header 名称、正则表达式,匹配 Header 中是否存在该名称且值与正则表达式匹配,示例配置:
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://nowjava.com
predicates:
- Header=name, ano.i
6、Host Route Predicate Factory
输入一个参数:Host Name 表达式列表,匹配 Header 中 Host 字段的值,示例配置:
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://nowjava.com
predicates:
- Host=**.nowjava.cn,**.nowjava.io
7、Method Route Predicate Factory
输入一个参数:HTTP Method,匹配请求方法,示例配置:
spring:
cloud:
gateway:
routes:
- id: method_route
uri: https://nowjava.com
predicates:
- Method=GET
8、Path Route Predicate Factory
输入两个参数:Spring PathMatcher
表达式列表、【可选】matchOptionalTrailingSeparator
标识,示例配置:
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://nowjava.com
predicates:
- Path=/foo/{segment},/bar/{segment}
9、Query Route Predicate Factory
输入两个参数:请求参数、【可选】正则表达式,匹配请求地址类似于 https://nowjava.com/test?hello=world&name=nowjava
所包含的 request params, 示例配置:
# 仅匹配是否包含参数 hello
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://nowjava.com
predicates:
- Query=hello
本文系作者在时代Java发表,未经许可,不得转载。
如有侵权,请联系nowjava@qq.com删除。