#!/usr/bin/env luajit
local cgi = require("cgi")
local req_params = require("req-params")
local str=""
if req_params.param("password") and req_params.param("password") == "401" then
cgi.render("401 Unauthorized",{["Content-Type"]="text/html"},401)
return
end
-- Access GET parameters
if next(req_params.get_params) then
str=str..m("h2","GET parameters:")
for k,v in pairs(req_params.get_params) do
str=str..k.." = "..v.."
"
end
end
-- Access POST parameters
if next(req_params.post_params) then
str=str..m("h2","POST parameters:")
for k,v in pairs(req_params.post_params) do
str=str..k.." = "..v.."
"
end
end
-- Combined helper
local name = req_params.param("name") or "anonymous"
str=str..m("p","Hello, "..name.."!")
cgi.render(m("html",
m("head",
m("title","ssg test")
)..
m("body",
m("h1","Hello from Lua CGI")..
m("p", "ssg test")..
m("p",_VERSION)..
str
)
),
{["Content-Type"]="text/html"},200)