spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
# 用日期时间匹配
spring:
cloud:
gateway:
routes:
- id: before_route
uri: https://example.org
predicates:
- Before=2017-01-20T17:42:47.789-07:00[America/Denver]
# 用日期时间匹配
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]
# 用日期时间匹配
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=chocolate, ch.p
# 用 cookie 名称和值匹配
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id, \d+
# 用 header 名称和值匹配
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Host=**.somehost.org,**.anotherhost.org
# 用 Host header 的值匹配
spring:
cloud:
gateway:
routes:
- id: method_route
uri: https://example.org
predicates:
- Method=GET,POST
# 用请求方法的类型匹配
spring:
cloud:
gateway:
routes:
- id: path_route
uri: https://example.org
predicates:
- Path=/red/{segment},/blue/{segment}
# 用请求路径的值匹配
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=green
# 用查询参数的名称和值(值可以省略)匹配
spring:
cloud:
gateway:
routes:
- id: remoteaddr_route
uri: https://example.org
predicates:
- RemoteAddr=192.168.1.1/24
# 用 RemoteAddr(CIDR格式,如:192.168.1.1/24) header 的值匹配
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
# 用分组名称和权重匹配
spring:
cloud:
gateway:
routes:
- id: xforwarded_remoteaddr_route
uri: https://example.org
predicates:
- XForwardedRemoteAddr=192.168.1.1/24
# 用 X-Forwarded-For(CIDR格式,如:192.168.1.1/24) header 值匹配
https://blog.csdn.net/abu935009066/article/details/112260405
添加请求头、添加请求参数、添加响应头、断路器、缓存请求体、去重响应头、回退头、JSON转gRPC、本地响应缓存、映射请求头、修改请求体、修改响应体、前缀路径、保留主机头、重定向、移除JSON属性响应体、移除请求头、移除请求参数、移除响应头、请求头大小、请求速率限制器、重写位置响应头、重写路径、重写响应头、保存会话、安全头、设置路径、设置请求头、设置响应头、设置状态、去除前缀、重试、请求大小、设置请求主机头、令牌中继等过滤器和默认过滤器。
https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#gatewayfilter-factories
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=chocolate, ch.p
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- name: Cookie
args:
name: chocolate
regexp: ch.p