内置的Predicate
1、请求时间匹配
- After Route Predicate Factory
- - After=2017-01-20T17:42:47.789-07:00[America/Denver]
- 与2017年1月20日17:42 Mountain Time(Denver)之后的所有请求相匹配
- Before Route Predicate Factory
- - Before=2017-01-20T17:42:47.789-07:00[America/Denver]
- 与2017年1月20日17:42 Mountain Time(Denver)之前的所有请求相匹配
- After Route Predicate Factory
- - Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
- 与2017年1月20日17:42之后和2017年1月21日17:42之前的任何请求相匹配
2、Cookie匹配
- Cookie Route Predicate Factory
- - Cookie=chocolate, ch.p
- 匹配请求具有名为
chocolate
who的值与ch.p
正则表达式匹配的cookie
3、Header匹配
- Header Route Predicate Factory
- - Header=X-Request-Id, \d+
- 请求头
X-Request-Id
其值与\d+
正则表达式匹配(具有一个或多个数字的值),则此路由匹配
4、Host匹配
- Host Route Predicate Factory
- - Host=**.somehost.org,**.anotherhost.org
- This route would match if the request has a
Host
header has the valuewww.somehost.org
orbeta.somehost.org
orwww.anotherhost.org
. - - {sub}.myhost.org
- 将URI模板变量(
sub
如上例中定义的)提取为名称和值的映射,并将其放在ServerWebExchange.getAttributes()
带有定义的键的位置ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE
5、Method匹配
- Method Route Predicate Factory
- - Method=GET
- 匹配请求方法为GET的请求
6、Path匹配
- Path Route Predicate Factory
- - Path=/foo/{segment},/bar/{segment}
- This route would match if the request path was, for example:
/foo/1
or/foo/bar
or/bar/baz
. - 将URI模板变量(
segment
如上例中定义的)提取为名称和值的映射,并将其放在ServerWebExchange.getAttributes()
带有定义的键的位置ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE
7、QueryParam匹配
- Query Route Predicate Factory
- - Query=baz
- This route would match if the request contained a
baz
query parameter. - - Query=foo, ba.
- 请求包含
foo
其值与ba.
regexp 匹配的查询参数,则此路由将匹配,因此bar
并且baz
将匹配
8、Remote匹配
- RemoteAddr Route Predicate Factory
- - RemoteAddr=192.168.1.1/24
- This route would match if the remote address of the request was, for example,
192.168.1.10
.****
配置
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]