2020-06-13 20:56:11 +08:00
|
|
|
|
<!--
|
|
|
|
|
#
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
#
|
|
|
|
|
-->
|
|
|
|
|
|
2020-08-12 22:54:11 +08:00
|
|
|
|
- [English](../../plugins/echo.md)
|
|
|
|
|
|
2020-06-13 20:56:11 +08:00
|
|
|
|
# 目录
|
|
|
|
|
- [**简介**](#简介)
|
|
|
|
|
- [**属性**](#属性)
|
|
|
|
|
- [**如何启用**](#如何启用)
|
|
|
|
|
- [**测试插件**](#测试插件)
|
|
|
|
|
- [**禁用插件**](#禁用插件)
|
|
|
|
|
|
|
|
|
|
## 简介
|
|
|
|
|
|
2020-06-18 09:24:55 +08:00
|
|
|
|
echo 是一个有用的插件,可帮助用户尽可能全面地了解如何开发APISIX插件。
|
2020-06-13 20:56:11 +08:00
|
|
|
|
|
|
|
|
|
|
2020-06-18 09:24:55 +08:00
|
|
|
|
该插件展示了如何在常见的 phase 中实现相应的功能,常见的 phase 有:init, rewrite, access, balancer, header filer, body filter 以及 log。
|
2020-06-13 20:56:11 +08:00
|
|
|
|
|
|
|
|
|
## 属性
|
|
|
|
|
|
|
|
|
|
|属性名称 |必选项 |描述|
|
|
|
|
|
|--------- |--------|-----------|
|
2020-06-18 09:24:55 +08:00
|
|
|
|
| before_body |可选| 在 body 属性之前添加的内容,如果 body 属性没有指定将添加在 upstream response body 之前。 |
|
|
|
|
|
| body |可选| 返回给客户端的响应内容,它将覆盖 upstream 返回的响应 body。 |
|
|
|
|
|
| after_body |可选| 在 body 属性之后添加的内容,如果 body 属性没有指定将在 upstream 响应 body 之后添加。 |
|
2020-06-13 20:56:11 +08:00
|
|
|
|
|
|
|
|
|
## 如何启用
|
|
|
|
|
|
|
|
|
|
1. 为特定路由启用 echo 插件。
|
|
|
|
|
|
|
|
|
|
```shell
|
2020-06-18 09:24:55 +08:00
|
|
|
|
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
|
2020-06-13 20:56:11 +08:00
|
|
|
|
{
|
|
|
|
|
"plugins": {
|
2020-06-18 09:24:55 +08:00
|
|
|
|
"echo": {
|
|
|
|
|
"before_body": "before the body modification "
|
|
|
|
|
}
|
2020-06-13 20:56:11 +08:00
|
|
|
|
},
|
|
|
|
|
"upstream": {
|
2020-06-18 09:24:55 +08:00
|
|
|
|
"nodes": {
|
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
|
},
|
|
|
|
|
"type": "roundrobin"
|
2020-06-13 20:56:11 +08:00
|
|
|
|
},
|
|
|
|
|
"uri": "/hello"
|
|
|
|
|
}'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 测试插件
|
|
|
|
|
|
|
|
|
|
* 成功:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
$ curl -i http://127.0.0.1:9080/hello
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
...
|
2020-06-18 09:24:55 +08:00
|
|
|
|
before the body modification hello world
|
2020-06-13 20:56:11 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 禁用插件
|
|
|
|
|
|
|
|
|
|
当您要禁用`echo`插件时,这很简单,您可以在插件配置中删除相应的json配置,无需重新启动服务,它将立即生效:
|
|
|
|
|
|
|
|
|
|
```shell
|
2020-06-18 09:24:55 +08:00
|
|
|
|
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d value='
|
2020-06-13 20:56:11 +08:00
|
|
|
|
{
|
|
|
|
|
"methods": ["GET"],
|
|
|
|
|
"uri": "/hello",
|
|
|
|
|
"plugins": {},
|
|
|
|
|
"upstream": {
|
|
|
|
|
"type": "roundrobin",
|
|
|
|
|
"nodes": {
|
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}'
|
|
|
|
|
```
|