Skip to content

Commit

Permalink
Signed-off-by: yutao04 <[email protected]>
Browse files Browse the repository at this point in the history
docs: add response-header-rewrite and static-downgrade plugin docs
  • Loading branch information
trickMin committed Oct 11, 2022
1 parent aaa1a4c commit 1894f66
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 7 deletions.
7 changes: 4 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
## 插件

* [插件界面配置引导](plugin/plugin-configuring-guide.md)

* [percent-limit](plugin/percent-limit.md)
* [static-downgrade](plugin/static-downgrade.md)
* [response-header-rewrite](plugin/response-header-rewrite.md)
* [ua-restriction](plugin/ua-restriction.md)

## 问题定位

* [问题定位引导](troubleshooting/troubleshooting.md)

* [问题定位引导](troubleshooting/troubleshooting.md)
9 changes: 5 additions & 4 deletions docs/plugin/percent-limit.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

## 属性

| 名称 | 类型 | 必选项 | 默认值 | 描述 |
|-------|--------|-----|-----|------------|
| 限流百分比 | number || - | 允许通过流量的百分比 |
| 名称 | 类型 | 必选项 | 范围 | 描述 |
|---------------|---------|-----|---------------|------------|
| kind | string || percent-limit | 插件类型(值固定) |
| limit_percent | integer || [0, 100] | 允许通过流量的百分比 |


## 前置条件

以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换
以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置

## 创建

Expand Down
47 changes: 47 additions & 0 deletions docs/plugin/response-header-rewrite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 响应头部重写

## 描述

`response-header-rewrite`插件对请求的响应头进行变更,包括新增、删除和修改操作

## 属性

| 名称 | 类型 | 必选项 | 默认值 | 范围 | 描述 |
|----------------------|--------|-----|--------|------------------------------|--------------|
| header[].headerKey | string || - | length <= 200 | 需要操作的响应头名称 |
| header[].operation | string || create | create<br/>update<br/>delete | 对响应的的操作类型 |
| header[].headerValue | string || - | length <= 200 | 对于响应头新增或修改的值 |


## 前置条件

以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置

## 创建

```shell
curl -XPOST -v -H "Content-Type:application/json" -d '{
"BindingObjectId": {{ 路由ID }},
"BindingObjectType": "routeRule",
"GwId": {{ 网关ID }},
"PluginConfiguration": "{\"header\":[\"headerKey\": \"testHeader\",\"operation\": \"update\",\"headerValue\": \"testHeaderValue\"]}",
"PluginType": "response-header-rewrite"
}' http://{{ hango-portal ip:port }}/gdashboard?Action=BindingPlugin&Version=2019-09-01
```

## 测试

```shell
## 基于如下基础curl命令,根据后端服务要求将请求具体化,观察响应中的头变化是否符合插件配置的预期(响应头是否新增、被修改或删除)
curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}"
```

## 删除

```shell
curl -v -H "Content-Type:application/json" http://{{ hango-portal ip:port }}/gdashboard?PluginBindingInfoId={{ 插件ID }}&Action=UnbindingPlugin&Version=2019-09-01
```

## 界面配置方法

[插件界面配置方法引导](plugin-configuring-guide.md)
66 changes: 66 additions & 0 deletions docs/plugin/static-downgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 静态降级

## 描述

`static-downgrade`插件可匹配指定的请求进行降级,返回指定的响应内容

## 属性

| 名称 | 类型 | 必选项 | 范围 | 描述 |
|-----------------------------------------|----------|-----|--------------------------------------------------------------------------------------|--------------|
| kind | string || static-downgrade | 插件类型(值固定) |
| condition.request.requestSwitch | boolean || - | 是否使用请求进行匹配 |
| condition.request.method | []string || GET<br/>POST<br/>PUT<br/>DELETE<br/>OPTIONS<br/>HEAD<br/>TRACE<br/>CONNECT<br/>PATCH | HTTP的请求方法类型 |
| condition.request.path.match_type | string || exact_match<br/>safe_regex_match | 请求路径匹配方式 |
| condition.request.path.value | string || - | 请求路径匹配内容 |
| condition.request.host.match_type | string || exact_match<br/>safe_regex_match | 请求域名匹配方式 |
| condition.request.host.value | string || - | 请求域名匹配内容 |
| condition.request.headers[].headerKey | string || - | 请求头匹配名称 |
| condition.request.headers[].match_type | string || exact_match<br/>safe_regex_match | 请求头匹配匹配方式 |
| condition.request.headers[].value | string || - | 请求头匹配匹配内容 |
| condition.response.code.match_type | string || exact_match<br/>safe_regex_match | 响应状态码匹配方式 |
| condition.response.code.value | integer || [200, 599] | 响应状态码匹配内容 |
| condition.response.headers[].headerKey | string || - | 响应头匹配名称 |
| condition.response.headers[].match_type | string || exact_match<br/>safe_regex_match | 响应头匹配方式 |
| condition.response.headers[].value | string || - | 响应头匹配内容 |
| response.code | integer || [200, 599] | 降级后返回的状态码 |
| response.headers[key] | string || - | 降级后返回的响应头 |
| response.headers[value] | string || - | 降级后返回的响应头对应值 |
| response.body | string || - | 降级后返回的body内容 |


## 前置条件

以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置

## 创建

```shell
curl -XPOST -v -H "Content-Type:application/json" -d '{
"BindingObjectId": {{ 路由ID }},
"BindingObjectType": "routeRule",
"GwId": {{ 网关ID }},
"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\"}}",
"PluginType": "static-downgrade"
}' http://{{ hango-portal ip:port }}/gdashboard?Action=BindingPlugin&Version=2019-09-01
```

## 测试

```shell
## 基于如下基本的curl命令,添加插件中配置的请求头、响应头等降级条件,测试是否返回配置的响应内容(响应码、响应头和响应体)
curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}"

## 例如,插件中配置了降级条件配置了一个响应头为"reqHeader: reqHeaderValue",则需要构造如下请求进行测试
curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}" -H "reqHeader:reqHeaderValue"
```

## 删除

```shell
curl -v -H "Content-Type:application/json" http://{{ hango-portal ip:port }}/gdashboard?PluginBindingInfoId={{ 插件ID }}&Action=UnbindingPlugin&Version=2019-09-01
```

## 界面配置方法

[插件界面配置方法引导](plugin-configuring-guide.md)
48 changes: 48 additions & 0 deletions docs/plugin/ua-restriction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# UA黑白名单

## 描述

`ua-restriction`插件可以针对来源于不同User-Agent(用户代理)的请求进行黑名单或白名单限制

## 属性

| 名称 | 类型 | 必选项 | 范围 | 描述 |
|-------------------|---------|-----|---------------------------------------------------|--------------------------|
| kind | string || ua-restriction | 插件类型(值固定) |
| type | integer || [0, 1] | UA黑白名单策略<br/>0:黑名单;1:白名单 |
| list[].match_type | string || exact_match<br/>prefix_match<br/>safe_regex_match | UA黑白名单策略 |
| list[].value | string || length <= 200 | User-Agent值 |


## 前置条件

以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置

## 创建

```shell
curl -XPOST -v -H "Content-Type:application/json" -d '{
"BindingObjectId": {{ 路由ID }},
"BindingObjectType": "routeRule",
"GwId": {{ 网关ID }},
"PluginConfiguration": "{\"type\":\"0\",\"list\":[{\"match_type\":\"exact_match\",\"value\":[\"testUA\"]}],\"kind\":\"ua-restriction\"}",
"PluginType": "ua-restriction"
}' http://{{ hango-portal ip:port }}/gdashboard?Action=BindingPlugin&Version=2019-09-01
```

## 测试

```shell
## 修改如下请求的User-Agent参数,与插件配置的UA值一致,测试黑白名单效果
curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}" -H "User-Agent:xxx"
```

## 删除

```shell
curl -v -H "Content-Type:application/json" http://{{ hango-portal ip:port }}/gdashboard?PluginBindingInfoId={{ 插件ID }}&Action=UnbindingPlugin&Version=2019-09-01
```

## 界面配置方法

[插件界面配置方法引导](plugin-configuring-guide.md)

0 comments on commit 1894f66

Please sign in to comment.