Closed beardlessCat closed 1 year ago
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 }
uname -a
the chart of apisix do not enabled the ext-plugin-post-resp . we need enable it by myself。
Issue description
When requesting services through the gateway, the ResponseFilter method in the plugin will not be executed。
The code is as follows
the config as flows:
Environment
uname -a
):Linux 5017 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux