spacewander commented on code in PR #107:
URL: 
https://github.com/apache/apisix-go-plugin-runner/pull/107#discussion_r980766417


##########
internal/http/response.go:
##########
@@ -75,6 +143,51 @@ func (r *Response) Write(b []byte) (int, error) {
        return r.body.Write(b)
 }
 
+func (r *Response) Var(name string) ([]byte, error) {
+       if r.vars == nil {
+               r.vars = map[string][]byte{}
+       }
+
+       var v []byte
+       var found bool
+
+       if v, found = r.vars[name]; !found {
+               var err error
+
+               builder := util.GetBuilder()
+               varName := builder.CreateString(name)
+               ei.VarStart(builder)
+               ei.VarAddName(builder, varName)
+               varInfo := ei.VarEnd(builder)
+               v, err = r.askExtraInfo(builder, ei.InfoVar, varInfo)
+               util.PutBuilder(builder)
+
+               if err != nil {
+                       return nil, err
+               }
+
+               r.vars[name] = v
+       }
+       return v, nil
+}
+
+func (r *Response) ReadBody() ([]byte, error) {
+       if len(r.a6Body) > 0 {
+               return r.a6Body, nil
+       }
+
+       builder := util.GetBuilder()
+       ei.ReqBodyStart(builder)
+       bodyInfo := ei.ReqBodyEnd(builder)
+       v, err := r.askExtraInfo(builder, ei.InfoRespBody, bodyInfo)

Review Comment:
   Builder is not put back after thing is done?



##########
internal/http/response.go:
##########
@@ -31,12 +38,73 @@ import (
 type Response struct {
        r *hrc.Req
 
+       conn            net.Conn
+       extraInfoHeader []byte
+
        hdr    *Header
        rawHdr http.Header
 
        statusCode int
 
        body *bytes.Buffer
+
+       vars map[string][]byte
+       // a6Body is read-only
+       a6Body []byte

Review Comment:
   Better to name this variable as originalBody or something similar?



##########
internal/http/response.go:
##########
@@ -158,10 +271,16 @@ func (r *Response) FetchChanges(builder 
*flatbuffers.Builder) bool {
        return true
 }
 
+func (r *Response) BindConn(c net.Conn) {
+       r.conn = c
+}
+
 func (r *Response) Reset() {
        r.body = nil
        r.statusCode = 0
        r.hdr = nil
+       r.conn = nil
+       r.vars = nil

Review Comment:
   Do we need to clean the original body?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to