-- this small Lua script demonstrates the use of Lua in (bozo)httpd
-- it will simply output the "environment"
-- Keep in mind that bozohttpd forks for each request when started in
-- daemon mode, you can set global veriables here, but they will have
-- the same value on each invocation. You can not keep state between
-- two calls.
local httpd = require 'httpd'
function printenv(env, headers, query)
-- we get the "environment" in the env table, the values are more
-- or less the same as the variable for a CGI program
if count == nil then
count = 1
end
-- output a header
print([[
Bozotic Lua Environment
Bozotic Lua Environment
]])
print('module version: ' .. httpd._VERSION .. '
')
print('Server Environment
')
-- print the list of "environment" variables
for k, v in pairs(env) do
print(k .. '=' .. v .. '
')
end
print('Request Headers
')
for k, v in pairs(headers) do
print(k .. '=' .. v .. '
')
end
if query ~= nil then
print('Query Variables
')
for k, v in pairs(query) do
print(k .. '=' .. v .. '
')
end
end
print('Form Test
')
print([[
]])
-- output a footer
print([[
]])
end
function form(env, header, query)
if query ~= nil then
print('Form Variables
')
if env.CONTENT_TYPE ~= nil then
print('Content-type: ' .. env.CONTENT_TYPE .. '
')
end
for k, v in pairs(query) do
print(k .. '=' .. v .. '
')
end
else
print('No values')
end
end
-- register this handler for http:////printenv
httpd.register_handler('printenv', printenv)
httpd.register_handler('form', form)