这是今天社区里的一位朋友遇到的问题, Control最后return回去的数据是一个table类型,而不是一个字符串,这时候Vanilla报错了。

社区里朋友的代码,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function ResController:fetchData()
local hc = http:new()
local resp, err = hc:request_uri("http://xxx.xxx.x.xx", {

metod = "GET"
path = "/sec/res/find?pid="..id,
headers = {
["User-Agent"] = "Mozilla/5.0..."
}

})
if not resp then
return "request error :"..err
end
return resp.body
end

在看一下Vanilla的代码是如何处理这个逻辑的:

vanilla的代码:

1
2
3
4
5
function Response:response()
local body = {[1]=self.append_body, [2]=self.body, [3]=self.prepend_body}
ngx.print(table.concat( body, ""))
return true
end