内置的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匹配请求具有名为chocolatewho的值与ch.p正则表达式匹配的cookie3、Header匹配
Header Route Predicate Factory - Header=X-Request-Id, \d+请求头X-Request-Id其值与\d+正则表达式匹配(具有一个或多个数字的值),则此路由匹配4、Host匹配
Host Route Predicate Factory - Host=**.somehost.org,**.anotherhost.orgThis route would match if the request has a Host header has the value www.somehost.org or beta.somehost.org or www.anotherhost.org.- {sub}.myhost.org将URI模板变量(sub如上例中定义的)提取为名称和值的映射,并将其放在ServerWebExchange.getAttributes()带有定义的键的位置ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE5、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_ATTRIBUTE7、QueryParam匹配
Query Route Predicate Factory - Query=bazThis 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/24This 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]