apache / apisix-go-plugin-runner

Go Plugin Runner for APISIX
https://apisix.apache.org/
Apache License 2.0
167 stars 69 forks source link

help request: I use go plugin runner write my own ext-plugin-post-resp: response-rewrite #119

Closed yunduansing closed 1 year ago

yunduansing commented 1 year ago

Description

pkgHTTP.Response.ReadBody() error: util/msg.go:56 read: truncated, only get the first 219260 bytes,but server.go receive rpc type: 101 data length: 6253172

where can I find the read max bytes config and update it?

my go code: ` cfg := conf.(ResponseRewriteConf) if cfg.Status > 0 { w.WriteHeader(cfg.Status) } else { w.WriteHeader(200) }

w.Header().Set("X-Resp-A6-Runner", "Go")
if len(cfg.Headers) > 0 {
    for k, v := range cfg.Headers {
        w.Header().Set(k, v)
    }
}

//body := []byte(cfg.Body)
originBody, err := w.ReadBody()
if err != nil {
    log.Errorf("failed to read response body: ", err)
    return
}

var heleResp = HeleResponse{
    ErrCode: w.StatusCode(),
}
if w.StatusCode() == 200 {
    heleResp.Data = originBody
} else {
    heleResp.ErrMsg = originBody
}

body, _ := json.Marshal(heleResp)

_, err = w.Write(body)
if err != nil {
    log.Errorf("failed to write: %s", err)
}`

Environment

soulbird commented 1 year ago

It seems to be the same problem as #114 , when the request or response data is too large, we need to read in a loop.

yunduansing commented 1 year ago

It seems to be the same problem as #114 , when the request or response data is too large, we need to read in a loop.

Yes, that's the problem. loop reading body can solve it