-- $NetBSD: printenv.lua,v 1.3.8.1 2021/03/27 13:38:51 martin Exp $ -- 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 variables here, but they will have -- the same value on each invocation. You can not keep state between -- two calls. -- You can test this example by running the following command: -- /usr/libexec/httpd -b -f -I 8080 -L test printenv.lua . -- and then navigate to: http://127.0.0.1:8080/test/printenv local httpd = require 'httpd' function escape_html(s) return s:gsub('&', '&'):gsub('<', '<'):gsub('>', '>'):gsub('"', '"') end 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 -- output headers using httpd.write() -- httpd.write() will not append newlines httpd.write("HTTP/1.1 200 Ok\r\n") httpd.write("Content-Type: text/html\r\n\r\n") -- output html using httpd.print() -- you can also use print() and io.write() but they will not work with SSL httpd.print([[