Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/libexec/httpd/printenv.lua,v rcsdiff: /ftp/cvs/cvsroot/src/libexec/httpd/printenv.lua,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.2 retrieving revision 1.2.18.1 diff -u -p -r1.2 -r1.2.18.1 --- src/libexec/httpd/printenv.lua 2014/01/02 08:21:38 1.2 +++ src/libexec/httpd/printenv.lua 2016/04/10 10:33:11 1.2.18.1 @@ -1,4 +1,4 @@ --- $NetBSD: printenv.lua,v 1.2 2014/01/02 08:21:38 mrg Exp $ +-- $NetBSD: printenv.lua,v 1.2.18.1 2016/04/10 10:33:11 martin Exp $ -- this small Lua script demonstrates the use of Lua in (bozo)httpd -- it will simply output the "environment" @@ -8,6 +8,10 @@ -- 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 printenv(env, headers, query) @@ -15,12 +19,14 @@ 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([[ + -- 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([[