Skip to content
Snippets Groups Projects
Commit b73631ca authored by Juan Diego Campo's avatar Juan Diego Campo
Browse files

Saco dependencia a una lib json

parent b5c0aec8
No related branches found
No related tags found
No related merge requests found
...@@ -18,16 +18,15 @@ function split(str, pat) ...@@ -18,16 +18,15 @@ function split(str, pat)
end end
function main() function main()
local json = require("json")
local JSON = (loadfile "JSON.lua")() local JSON = (loadfile "JSON.lua")()
local input = "{\n" local input = "{\n"
input = input.."\t\"unique_id\": "..json.encode(m.getvar("UNIQUE_ID"))..",\n" input = input.."\t\"unique_id\": \""..m.getvar("UNIQUE_ID").."\",\n"
input = input.."\t\"method\": "..json.encode(m.getvar("REQUEST_METHOD"))..",\n" input = input.."\t\"method\": \""..m.getvar("REQUEST_METHOD").."\",\n"
input = input.."\t\"protocol\": "..json.encode(m.getvar("REQUEST_PROTOCOL"))..",\n" input = input.."\t\"protocol\": \""..m.getvar("REQUEST_PROTOCOL").."\",\n"
input = input.."\t\"uri\": "..json.encode(m.getvar("REQUEST_URI"))..",\n" input = input.."\t\"uri\": \""..m.getvar("REQUEST_URI").."\",\n"
if m.getvar("REQUEST_BODY") then if m.getvar("REQUEST_BODY") then
input = input.."\t\"body\": "..json.encode(m.getvar("REQUEST_BODY"))..",\n" input = input.."\t\"body\": \""..m.getvar("REQUEST_BODY").."\",\n"
else else
input = input.."\t\"body\": \"\",\n" input = input.."\t\"body\": \"\",\n"
end end
...@@ -40,8 +39,8 @@ function main() ...@@ -40,8 +39,8 @@ function main()
args_get = split(args_get[#args_get],"&") args_get = split(args_get[#args_get],"&")
for i = 1, #args_get do for i = 1, #args_get do
arg = split(args_get[i],"=") arg = split(args_get[i],"=")
input = input.."\t\t"..json.encode(arg[1])..": " input = input.."\t\t\""..arg[1].."\": "
input = input..json.encode(arg[2]) input = input.."\""..arg[2].."\""
if i < #args_get then if i < #args_get then
input = input..",\n" input = input..",\n"
end end
...@@ -54,8 +53,8 @@ function main() ...@@ -54,8 +53,8 @@ function main()
headers = split(headers,"\n") headers = split(headers,"\n")
for i = 1, #headers do for i = 1, #headers do
header = split(headers[i],": ") header = split(headers[i],": ")
input = input.."\t\t"..json.encode(header[1])..": " input = input.."\t\t\""..header[1].."\": "
input = input..json.encode(header[2]) input = input.."\""..header[2].."\""
if i < #headers then if i < #headers then
input = input..",\n" input = input..",\n"
end end
...@@ -66,8 +65,8 @@ function main() ...@@ -66,8 +65,8 @@ function main()
-- local args_post = m.getvars("ARGS_POST") -- local args_post = m.getvars("ARGS_POST")
local args_post = {} local args_post = {}
for i = 1, #args_post do for i = 1, #args_post do
input = input.."\t\t"..json.encode(args_post[i].name)..": " input = input.."\t\t\""..args_post[i].name.."\": "
input = input..json.encode(args_post[i].value) input = input.."\""..args_post[i].value.."\""
if i < #args_post then if i < #args_post then
input = input..",\n" input = input..",\n"
end end
...@@ -91,7 +90,9 @@ function main() ...@@ -91,7 +90,9 @@ function main()
for line in p:lines() do for line in p:lines() do
output = output..line.."\n" output = output..line.."\n"
end end
os.remove(tmpfile) -- os.remove(tmpfile)
print(output)
local result = JSON:decode(output) local result = JSON:decode(output)
m.log(3, "ML - res:\n") m.log(3, "ML - res:\n")
...@@ -100,7 +101,7 @@ function main() ...@@ -100,7 +101,7 @@ function main()
end end
p:close() p:close()
m.setvar("tx.pepe","pepe")
return "ERROR"
return nil
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment