1、断言(Predicates)
(1)Path
配置请求路径的匹配规则
# yml配置,多个参数用逗号隔开
- Path = /aa/**,/bb/**
# json配置
{"name":"Path","args":{"pattern1":"/aa/**","pattern2":"/bb/**"}}
(2)Cookie
配置对Cookie中值的匹配,第一个为key,第二个为value
# yml配置
- Cookie = chocolate,ch.p
# json配置
{"name":"Cookie","args":{"_genkey_0":"chocolate","_genkey_1":"ch.p"}}
(3)Header
匹配Http请求中设置的内容,也是第一个为key,第二个为value,比如:http-header设置X-Request-Id:\d+可以匹配,第二个参数是正则表达式
# yml配置
- Header = X-Request-Id,\d+
# json配置
{"name":"Header","args":{"_genkey_0":"X-Request-Id","_genkey_1":"\d+"}}
(4)Host
匹配Http请求Host,比如:匹配所有host为**.somehost.com的请求, **为通配符
# yml配置
- Host = **.somehost.com
# json配置
{"name":"Host","args":{"_genkey_0":"**.somehost.com"}}
(5)Method
匹配Http请求方法
# yml配置
- Method = GET
# json配置
{"name":"Method","args":{"_genkey_0":"GET"}}
(6)Query
匹配Http请求中的查询参数,请求中携带param=value的请求可以匹配
# yml配置
- Query = param,value
# json配置
{"name":"Query","args":{"_genkey_0":"param","_genkey_1":"value"}}
(7)RemoteAddr
匹配请求中的Remote Address
# yml配置
- RemoteAddr = 192.168.1.1/24
# json配置
{"name":"RemoteAddr","args":{"_genkey_0":"192.168.1.1/24"}}
(8)After
设置该时间之后可以访问
# yml配置
- After = 2020-10-30T15:00:22.432+08:00[Asia/Shanghai]
# json配置
{"name":"After","args":{"_genkey_0":"2020-10-30T15:00:22.432+08:00[Asia/Shanghai]"}}
(9)Before
设置该时间之前可以访问
# yml配置
- Before = 2020-10-30T15:00:22.432+08:00[Asia/Shanghai]
# json配置
{"name":"Before","args":{"_genkey_0":"2020-10-30T15:00:22.432+08:00[Asia/Shanghai]"}
(10)Between
设置时间段内可以访问
# yml配置
- Between = 2020-10-30T15:00:22.432+08:00[Asia/Shanghai],2021-10-30T15:00:22.432+08:00[Asia/Shanghai]
# json配置
{"name":"Between","args":{"_genkey_0":"2020-10-30T15:00:22.432+08:00[Asia/Shanghai]","_genkey_1":"2021-10-30T15:00:22.432+08:00[Asia/Shanghai]"}}
(11)Weight
至少两组以上路由可以配置权重路由,配置后会根据权重随机访问几个路由
# yml配置
- Weight = service,80
# json配置
{"name":"Weight","args":{"_genkey_0":"service","_genkey_1":"80"}}
2、过滤器(Filters)
(1)RewritePath
重写请求的路径
# yml配置
- RewritePath = /path/(?<segment>.*), /$\{segment}
# json配置
{"name":"RewritePath","args":{"_genkey_0":"/foo/(?<segment>.*)","_genkey_1":"/$\\{segment}"}}
(2)AddRequestHeader
添加请求头
# yml配置
- AddRequestHeader = X-Request-Foo,Bar
# json配置
{"name":"AddRequestHeader","args":{"_genkey_0":"X-Request-Foo","_genkey_1":"Bar"}}
(3)AddRequestParameter
添加请求参数
# yml配置
- AddRequestParameter = foo,bar
# json配置
{"name":"AddRequestParameter","args":{"_genkey_0":"foo","_genkey_1":"bar"}}
(4)AddResponseHeader
添加响应头
# yml配置
- AddResponseHeader = X-Response-Foo,Bar
# json配置
{"name":"AddResponseHeader","args":{"_genkey_0":"X-Response-Foo","_genkey_1":"Bar"}}
(5)PrefixPath
添加路径前缀,比如:请求路径/test,被替换成/my/test
# yml配置
- PrefixPath = /my
# json配置
{"name":"PrefixPath","args":{"_genkey_0":"/my"}}
(6)StripPrefix
删除路径前缀,比如:请求路径/service/my/test,去除掉前面两个前缀之后,最后转发到目标服务的路径为/test
# yml配置
- StripPrefix = 2
# json配置
{"name":"StripPrefix","args":{"_genkey_0":"2"}}
(7)PreserveHostHeader
请求携带保留原始Host
# yml配置
- PreserveHostHeader
# json配置
{"name":"PreserveHostHeader","args":{}}
(8)RedirectTo
重定向,302是HTTP状态码
# yml配置
- RedirectTo = 302,http://example.org
# json配置
{"name":"RedirectTo","args":{"_genkey_0":"302","_genkey_1":"http://example.org"}}
(9)Hystrix
熔断
# yml配置
- name: Hystrix
args:
# 熔断后跳转地址
name: fallbackcmd
fallbackUri: forward:/failure
# json配置
{"name":"Hystrix","args":{"name":"fallbackcmd","fallbackUri":"forward:/failure"}}
(10)RequestRateLimiter
集成Redis原生支持请求限流
# yml配置
- name: RequestRateLimiter
args:
redis-rate-limiter.replenishRate: 10 #允许用户每秒执行多少请求,而不会丢弃任何请求
redis-rate-limiter.burstCapacity: 20 #允许在一秒钟内完成的最大请求数,将此值设置为零将阻止所有请求
# json配置
{"name":"RequestRateLimiter","args":{"redis-rate-limiter.replenishRate":"10","redis-rate-limiter.burstCapacity":"20"}}
(11)RemoveRequestHeader
删除请求头属性
# yml配置
- RemoveRequestHeader = X-Request-Foo
# json配置
{"name":"RemoveRequestHeader","args":{"_genkey_0":"X-Request-Foo"}}
(12)RemoveResponseHeader
删除响应头属性
# yml配置
- RemoveResponseHeader = X-Response-Foo
# json配置
{"name":"RemoveResponseHeader","args":{"_genkey_0":"X-Response-Foo"}}
(13)RewriteResponseHeader
重写响应头,比如:将响应头中X-Response-Foo的值user=admin&password=111111&status=N, 改为 user=admin&password=123456&status=N
# yml配置
- RewriteResponseHeader = X-Response-Foo,password=111111,password=123456
# json配置
{"name":"RewriteResponseHeader","args":{"_genkey_0":"X-Response-Foo","_genkey_1":"password=111111","_genkey_2":"password=123456"}}
(14)SetPath
重设请求路径,比如:请求/service/my/test,被改为/test
# yml配置
- SetPath =/test
# json配置
{"name":"SetPath","args":{"_genkey_0":"/test"}}
(15)SetResponseHeader
设置响应头,比如:将X-Response-Foo的值设置为test
# yml配置
- SetResponseHeader =X-Response-Foo,test
# json配置
{"name":"SetResponseHeader","args":{"_genkey_0":"X-Response-Foo","_genkey_1":"test"}}
(16)SetStatus
设置响应状态码,将当前响应的状态码设置为401
# yml配置
- name: SetStatus
args:
status: 401
# json配置
{"name":"SetStatus","args":{"_genkey_0":"401"}}
(17)SetRequestSize
设置文件传输大小
# yml配置
- name: RequestSize
args:
maxSize: 5000000
# json配置
{"name":"RequestSize","args":{"_genkey_0":"5000000"}}
(18)Retry
失败重试
# yml配置
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY
# json配置
{"name":"Retry","args":{"retries":"3","statuses":"BAD_GATEWAY"}}