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: How to get pkgHTTP.Request in ResponseFilter? #153

Open
zxyao145 opened this issue Dec 29, 2023 · 2 comments
Open

request help: How to get pkgHTTP.Request in ResponseFilter? #153

zxyao145 opened this issue Dec 29, 2023 · 2 comments

Comments

@zxyao145
Copy link

Issue description

I am trying to get pkgHTTP.Request in ResponseFilter method. I have modified the HTTPRespCall method in apisix-go-plugin-runner/internal/plugin/plugin.go as follows:

func HTTPRespCall(buf []byte, conn net.Conn) (*flatbuffers.Builder, error) {
+	req := inHTTP.CreateRequest(buf)
+	req.BindConn(conn)
+	defer inHTTP.ReuseRequest(req)

	resp := inHTTP.CreateResponse(buf)
	resp.BindConn(conn)
	defer inHTTP.ReuseResponse(resp)

	token := resp.ConfToken()
	conf, err := GetRuleConf(token)
	if err != nil {
		return nil, err
	}

+	err = ResponsePhase.filter(conf, resp, req)
       
       // ....
}

But I found that all the properties I received was empty. How should I handle it?

request: &{r:0xc0003ea860 conn:0xc0000122d8 extraInfoHeader:[] path:[] hdr:0xc0000122e8 rawHdr:map[] args:map[] rawArgs:map[] vars:map[] body:[] ctx:0xc00049d5c0 cancel:0x531ae0 respHdr:map[]}%!(EXTRA http.Header=map[])

If this modification is completed, I am willing to submit a PR.

Environment

  • APISIX Go Plugin Runner's version: latest
  • APISIX version: 3.6.0
  • Go version: 1.19.4
  • OS (cmd: uname -a): debian
@muhammadn
Copy link

@zxyao145 Just use res.Var("") to get the request data.

Example: method, err := res.Var("request_method")

List of nginx variables can be seen in the nginx documentation.

@zxyao145
Copy link
Author

een in the nginx documentation.nginx 变量列表可以在 nginx 文档中查看。

@zxyao145 Just use res.Var("") to get the request data.

Example: method, err := res.Var("request_method")

List of nginx variables can be seen in the nginx documentation.

Thanks a lot! I am glad to receive your reply. Recently, I have been busy with other things and do not have time to do work related to Apisix. If there are any conclusions, I will synchronize again.

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

2 participants