|
| 1 | +# 静态降级 |
| 2 | + |
| 3 | +## 描述 |
| 4 | + |
| 5 | +`static-downgrade`插件可匹配指定的请求进行降级,返回指定的响应内容 |
| 6 | + |
| 7 | +## 属性 |
| 8 | + |
| 9 | +| 名称 | 类型 | 必选项 | 范围 | 描述 | |
| 10 | +|-----------------------------------------|----------|-----|--------------------------------------------------------------------------------------|--------------| |
| 11 | +| kind | string | 是 | static-downgrade | 插件类型(值固定) | |
| 12 | +| condition.request.requestSwitch | boolean | 是 | - | 是否使用请求进行匹配 | |
| 13 | +| condition.request.method | []string | 否 | GET<br/>POST<br/>PUT<br/>DELETE<br/>OPTIONS<br/>HEAD<br/>TRACE<br/>CONNECT<br/>PATCH | HTTP的请求方法类型 | |
| 14 | +| condition.request.path.match_type | string | 否 | exact_match<br/>safe_regex_match | 请求路径匹配方式 | |
| 15 | +| condition.request.path.value | string | 否 | - | 请求路径匹配内容 | |
| 16 | +| condition.request.host.match_type | string | 否 | exact_match<br/>safe_regex_match | 请求域名匹配方式 | |
| 17 | +| condition.request.host.value | string | 否 | - | 请求域名匹配内容 | |
| 18 | +| condition.request.headers[].headerKey | string | 否 | - | 请求头匹配名称 | |
| 19 | +| condition.request.headers[].match_type | string | 否 | exact_match<br/>safe_regex_match | 请求头匹配匹配方式 | |
| 20 | +| condition.request.headers[].value | string | 否 | - | 请求头匹配匹配内容 | |
| 21 | +| condition.response.code.match_type | string | 是 | exact_match<br/>safe_regex_match | 响应状态码匹配方式 | |
| 22 | +| condition.response.code.value | integer | 是 | [200, 599] | 响应状态码匹配内容 | |
| 23 | +| condition.response.headers[].headerKey | string | 否 | - | 响应头匹配名称 | |
| 24 | +| condition.response.headers[].match_type | string | 否 | exact_match<br/>safe_regex_match | 响应头匹配方式 | |
| 25 | +| condition.response.headers[].value | string | 否 | - | 响应头匹配内容 | |
| 26 | +| response.code | integer | 是 | [200, 599] | 降级后返回的状态码 | |
| 27 | +| response.headers[key] | string | 是 | - | 降级后返回的响应头 | |
| 28 | +| response.headers[value] | string | 是 | - | 降级后返回的响应头对应值 | |
| 29 | +| response.body | string | 否 | - | 降级后返回的body内容 | |
| 30 | + |
| 31 | + |
| 32 | +## 前置条件 |
| 33 | + |
| 34 | +以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置 |
| 35 | + |
| 36 | +## 创建 |
| 37 | + |
| 38 | +```shell |
| 39 | +curl -XPOST -v -H "Content-Type:application/json" -d '{ |
| 40 | + "BindingObjectId": {{ 路由ID }}, |
| 41 | + "BindingObjectType": "routeRule", |
| 42 | + "GwId": {{ 网关ID }}, |
| 43 | + "PluginConfiguration": "{\"condition\":{\"request\":{\"requestSwitch\":true,\"method\":[\"GET\",\"POST\"],\"path\":{\"match_type\":\"exact_match\",\"value\":\"/rootpath/subpath\"},\"headers\":[{\"headerKey\":\"reqHeader\",\"match_type\":\"exact_match\",\"value\":\"reqHeaderValue\"}]},\"response\":{\"code\":{\"match_type\":\"safe_regex_match\",\"value\":\"503\"},\"headers\":[{\"headerKey\":\"rspHeader\",\"match_type\":\"exact_match\",\"value\":\"rspHeaderValue\"}]}},\"kind\":\"static-downgrade\",\"response\":{\"headers\":{\"downgradeHeader\":\"downgradeHeaderValue\"},\"code\":\"200\",\"body\":\"Test Response Context\"}}", |
| 44 | + "PluginType": "static-downgrade" |
| 45 | +}' http://{{ hango-portal ip:port }}/gdashboard?Action=BindingPlugin&Version=2019-09-01 |
| 46 | +``` |
| 47 | + |
| 48 | +## 测试 |
| 49 | + |
| 50 | +```shell |
| 51 | +## 基于如下基本的curl命令,添加插件中配置的请求头、响应头等降级条件,测试是否返回配置的响应内容(响应码、响应头和响应体) |
| 52 | +curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}" |
| 53 | + |
| 54 | +## 例如,插件中配置了降级条件配置了一个响应头为"reqHeader: reqHeaderValue",则需要构造如下请求进行测试 |
| 55 | +curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}" -H "reqHeader:reqHeaderValue" |
| 56 | +``` |
| 57 | + |
| 58 | +## 删除 |
| 59 | + |
| 60 | +```shell |
| 61 | +curl -v -H "Content-Type:application/json" http://{{ hango-portal ip:port }}/gdashboard?PluginBindingInfoId={{ 插件ID }}&Action=UnbindingPlugin&Version=2019-09-01 |
| 62 | +``` |
| 63 | + |
| 64 | +## 界面配置方法 |
| 65 | + |
| 66 | +[插件界面配置方法引导](plugin-configuring-guide.md) |
0 commit comments