Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
beardlessCat opened this issue Apr 8, 2023 · 1 comment
Closed

Comments

@beardlessCat
Copy link

beardlessCat commented Apr 8, 2023

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

  • APISIX Go Plugin Runner's version: 0.5.0
  • APISIX version:3.2.0
  • Go version:1.17.6
  • OS (cmd: uname -a):Linux 5017 3.10.0-1127.el7.x86_64 ci: enable #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
@beardlessCat
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant