1 -- $NetBSD: printenv.lua,v 1.2 2014/01/02 08:21:38 mrg Exp $
3 -- this small Lua script demonstrates the use of Lua in (bozo)httpd
4 -- it will simply output the "environment"
6 -- Keep in mind that bozohttpd forks for each request when started in
7 -- daemon mode, you can set global veriables here, but they will have
8 -- the same value on each invocation. You can not keep state between
11 local httpd
= require
'httpd'
13 function printenv(env
, headers
, query
)
15 -- we get the "environment" in the env table, the values are more
16 -- or less the same as the variable for a CGI program
26 <title>Bozotic Lua Environment</title>
29 <h1>Bozotic Lua Environment</h1>
32 print('module version: ' .. httpd
._VERSION
.. '<br>')
34 print('<h2>Server Environment</h2>')
35 -- print the list of "environment" variables
36 for k
, v
in pairs(env
) do
37 print(k
.. '=' .. v
.. '<br/>')
40 print('<h2>Request Headers</h2>')
41 for k
, v
in pairs(headers
) do
42 print(k
.. '=' .. v
.. '<br/>')
46 print('<h2>Query Variables</h2>')
47 for k
, v
in pairs(query
) do
48 print(k
.. '=' .. v
.. '<br/>')
52 print('<h2>Form Test</h2>')
55 <form method="POST" action="/rest/form?sender=me">
56 <input type="text" name="a_value">
67 function form(env
, header
, query
)
69 print('<h2>Form Variables</h2>')
71 if env
.CONTENT_TYPE
~= nil then
72 print('Content-type: ' .. env
.CONTENT_TYPE
.. '<br>')
75 for k
, v
in pairs(query
) do
76 print(k
.. '=' .. v
.. '<br/>')
83 -- register this handler for http://<hostname>/<prefix>/printenv
84 httpd
.register_handler('printenv', printenv
)
85 httpd
.register_handler('form', form
)