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

Open zxyao145 opened 6 months ago

zxyao145 commented 6 months ago

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

muhammadn commented 4 months ago

@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 commented 3 months ago

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.