sniper-xx opened a new issue #4074:
URL: https://github.com/apache/apisix/issues/4074


   ### Issue description
   I want to developing a plugin of apisix to fulfill unified format 
encapsulation. for example:
   ```json
   {
     "status": 200,
     "msg": "ok",
     "data":  "datas real response from backend server..."
   }
   ```
   I writed a plugin , override the  _M.body_filter method, but the funcation 
is not work correct. the code:
   ```lua
   function _M.body_filter(conf, ctx)
       core.log.error("------------------body_filter--------->")
       local result = {
           msg="ok",
           code=status_code,
           success=true
       }
   
       local isFinished = ngx.arg[2]
       local resp_code = tonumber(status_code)
   
       if not isFinished then
           backend_content = backend_content..ngx.arg[1]
           core.log.error("reading:----------------> 
",string.len(backend_content))
           ngx.arg[2] = false
       end
   
       if isFinished then
           --ngx.arg[2] = false
           core.log.error("end:----------------> ",ngx.arg[1])
           core.log.error("ending:======================> 
",string.len(backend_content))
           --local r = "{\"mystatus\":200,\"data\":"..backend_content.."}";
           result['data'] = cjson_decode(backend_content)
           --ngx.arg[2] = true
           ngx.arg[1] = cjson_encode(result)
           ngx.arg[2] = true
       end
   
   end
   ```
   
   the error is: 
   1、sometimes the client browser is not receive integrated json ;
   2、the cjson_decode is error, printed error is : Expected end but 
to_obejct_begin.
   
   My Question is how to implements the uniform data form wrap?  please.
   
   ### Environment
   
   * apisix version (cmd: `apisix version`):
   * OS (cmd: `uname -a`):
   * OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   * etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   * apisix-dashboard version, if have:
   


-- 
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.

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


Reply via email to