From d302872f3ab4ec1870e93037b012019566fc554c Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Tue, 25 Aug 2026 00:28:39 -0500 Subject: reorginization --- cgi.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 cgi.lua (limited to 'cgi.lua') diff --git a/cgi.lua b/cgi.lua new file mode 100755 index 0000000..5033984 --- /dev/null +++ b/cgi.lua @@ -0,0 +1,52 @@ +local cgi={} + +cgi.newline=false + +function cgi.tag(key,value,attrib) + local ret_str="<"..key + + if (attrib) then + for a_key,a_val in pairs(attrib) do + ret_str=ret_str.." "..a_key..'="'..a_val..'"' + end + end + + ret_str=ret_str..">" + if cgi.newline==true then ret_str=ret_str.."\n" end + + ret_str=ret_str..value + + if cgi.newline==true then ret_str=ret_str.."\n" end + + ret_str=ret_str.."" + + if cgi.newline==true then ret_str=ret_str.."\n" end + + return ret_str +end + +local function get_phrase(code) + local cases={ + [200]="OK", + [401]="Unauthorized", + } + if(cases[code]) then return cases[code] else return "" end +end + +function cgi.header(code,headers) + print("Status: "..code.." "..get_phrase(code)) + for h_name,header in pairs(headers) do + print(h_name..": "..header) + end + print() +end + +function cgi.render(content,headers,code) + headers["Content-Length"] = tostring(content:len()+1) + cgi.header(code,headers) + print(content); +end + +_G.m = cgi.tag + +return cgi -- cgit v1.3