How much the size of ngx.arg[1] could be

In body_filter phase, I want to return all result once like ResponseTransformer plugin do.
If the size of the result is too big, I can’t get it from the client, instead 502 bad gateway, and no error logs found.
How can I adjust some certain configs to make it response successfully with big result regardless of the time it may consume?

function ResponseTransformerHandler:body_filter(conf)
  if is_body_transform_set(conf) and is_json_body(kong.response.get_header("Content-Type")) then
    local ctx = ngx.ctx
    local chunk, eof = ngx.arg[1], ngx.arg[2]

    ctx.rt_body_chunks = ctx.rt_body_chunks or {}
    ctx.rt_body_chunk_number = ctx.rt_body_chunk_number or 1

    if eof then
      local chunks = concat(ctx.rt_body_chunks)
      local body = body_transformer.transform_json_body(conf, chunks)
      ngx.arg[1] = body or chunks

    else
      ctx.rt_body_chunks[ctx.rt_body_chunk_number] = chunk
      ctx.rt_body_chunk_number = ctx.rt_body_chunk_number + 1
      ngx.arg[1] = nil
    end
  end

end