I'm attempting to parse an XML coming in via a POST call in nginx with. I created a simple lua script that ngnix will use
local xml2lua = require("xml2lua")
local handler = require("xmlhandler.tree")
local function process()
ngx.req.read_body()
local req_body = ngx.req.get_body_data()
ngx.log(ngx.STDERR, "Type of body " .. type(req_body))
ngx.log(ngx.STDERR, "the body" .. req_body)
local thehandler = handler:new()
local theparser = xml2lua.parser(thehandler)
theparser:parse(req_body)
ngx.say(xml2lua.printable(thehandler.root))
for i, p in pairs(thehandler.root.top) do
-- print("table size " .. table.maxn(p))
ngx.say(i .. " Test " .. p.inner)
end
end
return process
Then I post some simple xml
`
DataMoreDataSomeMoreData
`
I can print the xml body to the nginx logs but I get this error with regards to the lua table from the xml.
`
10.7.1.87, server: , request: "POST / HTTP/1.1", host: "10.4.2.231:8080"
2020/08/06 17:42:20 [] 8155#8155: *4 [lua] osphandler.lua:8: the body
I'm attempting to parse an XML coming in via a POST call in nginx with. I created a simple lua script that ngnix will use
Then I post some simple xml `
`
I can print the xml body to the nginx logs but I get this error with regards to the lua table from the xml. ` 10.7.1.87, server: , request: "POST / HTTP/1.1", host: "10.4.2.231:8080" 2020/08/06 17:42:20 [] 8155#8155: *4 [lua] osphandler.lua:8: the body
, client: 10.7.1.87, server: , request: "POST / HTTP/1.1", host: "10.4.2.231:8080" 2020/08/06 17:42:20 [error] 8155#8155: *4 lua entry thread aborted: runtime error: /home/ec2-user/work//src/osphandler.lua:16: attempt to index field 'inner' (a nil value) stack traceback: coroutine 0: /home/ec2-user/work//src/osphandler.lua: in function </home/ec2-user/work//src/osphandler.lua:4> `
I'm new to lua so forgive any obvious issues as they aren't obvious to me.