ext-plugin-post-resp

Description

The ext-plugin-post-resp Plugin is for running specific external Plugins in the Plugin Runner before executing the built-in Lua Plugins.

The ext-plugin-post-resp plugin will be executed after the request gets a response from the upstream.

This plugin uses lua-resty-http library under the hood to send requests to the upstream, due to which the proxy-control, proxy-mirror, and proxy-cache plugins are not available to be used alongside this plugin. Also, mTLS Between APISIX and Upstream is not yet supported.

See External Plugin to learn more.

ext-plugin-post-resp - 图1note

Execution of External Plugins will affect the response of the current request.

Attributes

NameTypeRequiredDefaultValid valuesDescription
confarrayFalse[{“name”: “ext-plugin-A”, “value”: “{\”enable\”:\”feature\”}”}]List of Plugins and their configurations to be executed on the Plugin Runner.
allow_degradationbooleanFalsefalseSets Plugin degradation when the Plugin Runner is not available. When set to true, requests are allowed to continue.

Enable Plugin

The example below enables the ext-plugin-post-resp Plugin on a specific Route:

ext-plugin-post-resp - 图2note

You can fetch the admin_key from config.yaml and save to an environment variable with the following command:

  1. admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g')
  1. curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '
  2. {
  3. "uri": "/index.html",
  4. "plugins": {
  5. "ext-plugin-post-resp": {
  6. "conf" : [
  7. {"name": "ext-plugin-A", "value": "{\"enable\":\"feature\"}"}
  8. ]
  9. }
  10. },
  11. "upstream": {
  12. "type": "roundrobin",
  13. "nodes": {
  14. "127.0.0.1:1980": 1
  15. }
  16. }
  17. }'

Example usage

Once you have configured the External Plugin as shown above, you can make a request to execute the Plugin:

  1. curl -i http://127.0.0.1:9080/index.html

This will reach the configured Plugin Runner and the ext-plugin-A will be executed.

Delete Plugin

To remove the ext-plugin-post-resp Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '
  2. {
  3. "uri": "/index.html",
  4. "upstream": {
  5. "type": "roundrobin",
  6. "nodes": {
  7. "127.0.0.1:1980": 1
  8. }
  9. }
  10. }'