Openresty - Lua - concatinating strings to a table value

Viewed 20

I'm currently using the following LUA code to log nginx request details within openresty:

json = require("cjson")

local data = {request={}, response={}}

local req = data["request"]
local resp = data["response"]

req["method"] = ngx.req.get_method()
req["uri"] = ngx.var.uri

local postArgs = ngx.req.get_post_args()
local postArgs = "\"" .. postArgs .. "\""
req["post_args"] = postArgs



resp["status"] = ngx.status
resp["time"] = ngx.now()
resp["body"] = ngx.var.response_body

ngx.log(ngx.CRIT, json.encode(data));

Although I run into the following error:

lua:22: attempt to concatenate local 'postArgs' (a table value)

I've tried doing different forms of this but none seem to work due to one being a table and the other a string, is there an easy way to do what I'm trying to achieve, enclosing a particular value in speech marks before its added in table like in this example?

0 Answers
Related