apache / apisix-go-plugin-runner

Go Plugin Runner for APISIX
https://apisix.apache.org/
Apache License 2.0
167 stars 69 forks source link

request help: The ext-plugin-post-resp is not working properly #134

Closed beardlessCat closed 1 year ago

beardlessCat commented 1 year ago

Issue description

When requesting services through the gateway, the ResponseFilter method in the plugin will not be executed。

The code is as follows

func init() {
    err := plugin.RegisterPlugin(&MyRewriteResponse{})
    if err != nil {
        log.Fatalf("failed to register plugin MyRewriteResponse: %s", err)
    }
}

// it to the upstream.
type MyRewriteResponse struct {
    // Embed the default plugin here,
    // so that we don't need to reimplement all the methods.
    plugin.DefaultPlugin
}

type MyRewriteResponseConf struct {
    Tag string `json:"tag"`
}

func (p *MyRewriteResponse) Name() string {
    return "my-rewrite-response"
}

func (p *MyRewriteResponse) ParseConf(in []byte) (interface{}, error) {
    conf := MyRewriteResponseConf{}
    err := json.Unmarshal(in, &conf)
    return conf, err
}

func (p *MyRewriteResponse) ResponseFilter(conf interface{}, w pkgHTTP.Response) {
    w.Header().Set("responseid", uuid.New().String())
    tag := conf.(MyRewriteResponseConf).Tag
    if len(tag) > 0 {
        _, err := w.Write([]byte(tag))
        if err != nil {
            log.Errorf("failed to write: %s", err)
        }
    }
}

the config as flows:

{
  "uri": "/user/*",
  "name": "用户服务",
  "desc": "用户服务",
  "methods": [
    "GET",
    "POST",
    "PUT",
    "DELETE",
    "PATCH",
    "HEAD",
    "OPTIONS",
    "CONNECT",
    "TRACE",
    "PURGE"
  ],
  "plugins": {
    "ext-plugin-post-resp": {
      "_meta": {
        "disable": false
      },
      "conf": [
        {
          "name": "my-rewrite-response",
          "value": "{\"tag\":\"hello my-rewrite-response\"}"
        }
      ]
    }
  },
  "upstream_id": "454615881717122005",
  "labels": {
    "API_VERSION": "V1"
  },
  "status": 1
}

image

Environment

beardlessCat commented 1 year ago

the chart of apisix do not enabled the ext-plugin-post-resp . we need enable it by myself。 image