1.The After Route Predicate Factory
After路由谓词工厂接受一个参数,一个日期时间(它是一个java ZonedDateTime)。此谓词匹配在指定日期时间之后发生的请求。
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=red, gree.
2.The Before Route Predicate Factory
Before路由谓词工厂接受一个参数,一个日期时间(它是一个java ZonedDateTime)。此谓词匹配在指定日期时间之前发生的请求
spring:
cloud:
gateway:
routes:
- id: before_route
uri: https://example.org
predicates:
- Before=2017-01-20T17:42:47.789-07:00[America/Denver]
3.The Between Route Predicate Factory
Between路由谓词工厂接受两个参数,datetime1和datetime2,它们是java ZonedDateTime对象。此谓词匹配发生在datetime1之后和datetime2之前的请求。datetime2参数必须在datetime1之后。
spring:
cloud:
gateway:
routes:
- id: between_route
uri: https://example.org
predicates:
- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
4.The Cookie Route Predicate Factory
Cookie路由谓词工厂接受两个参数,即Cookie名称和regexp(这是一个Java正则表达式)。此谓词匹配具有给定名称且其值与正则表达式匹配的cookie
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=chocolate, ch.p
5.The Header Route Predicate Factory
Header路由谓词工厂接受两个参数,Header和regexp(这是一个Java正则表达式)。此谓词与具有给定名称的标头匹配,该名称的值与正则表达式匹配。
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id, \d+
6.The Host Route Predicate Factory
Host路由谓词工厂接受一个参数:主机名模式列表。该模式是Ant样式的模式。作为分离器。此谓词与匹配模式的Host标头相匹配。
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Host=**.somehost.org,**.anotherhost.org
7.The Method Route Predicate Factory
Method路由谓词工厂接受一个方法参数,该参数是一个或多个参数:要匹配的HTTP方法
spring:
cloud:
gateway:
routes:
- id: method_route
uri: https://example.org
predicates:
- Method=GET,POST
8.The Path Route Predicate Factory
路径路由谓词工厂采用两个参数:Spring PathMatcher模式列表和名为matchTrailingFlash的可选标志(默认为true)。
spring:
cloud:
gateway:
routes:
- id: path_route
uri: https://example.org
predicates:
- Path=/red/{segment},/blue/{segment}
9.The Query Route Predicate Factory
Query路由谓词工厂接受两个参数:一个必需的param和一个可选的regexp(它是Java正则表达式)。
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=green
10.The RemoteAddr Route Predicate Factory
RemoteAddr路由谓词工厂获取源的列表(最小大小1),这些源是CIDR表示法(IPv4或IPv6)字符串,例如192.168.0.1/16(其中192.168.0.1是IP地址,16是子网掩码)
spring:
cloud:
gateway:
routes:
- id: remoteaddr_route
uri: https://example.org
predicates:
- RemoteAddr=192.168.1.1/24
11.The Weight Route Predicate Factory
Weight路由谓词工厂接受两个参数:group和Weight(一个int)。重量按每组计算。
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