Remove building with NOCRYPTO option
[minix.git] / libexec / httpd / printenv.lua
blob5b0fdf9c66ac64f5f98a0f3e2456a66093b280ff
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
9 -- two calls.
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
18 if count == nil then
19 count = 1
20 end
22 -- output a header
23 print([[
24 <html>
25 <head>
26 <title>Bozotic Lua Environment</title>
27 </head>
28 <body>
29 <h1>Bozotic Lua Environment</h1>
30 ]])
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/>')
38 end
40 print('<h2>Request Headers</h2>')
41 for k, v in pairs(headers) do
42 print(k .. '=' .. v .. '<br/>')
43 end
45 if query ~= nil then
46 print('<h2>Query Variables</h2>')
47 for k, v in pairs(query) do
48 print(k .. '=' .. v .. '<br/>')
49 end
50 end
52 print('<h2>Form Test</h2>')
54 print([[
55 <form method="POST" action="/rest/form?sender=me">
56 <input type="text" name="a_value">
57 <input type="submit">
58 </form>
59 ]])
60 -- output a footer
61 print([[
62 </body>
63 </html>
64 ]])
65 end
67 function form(env, header, query)
68 if query ~= nil then
69 print('<h2>Form Variables</h2>')
71 if env.CONTENT_TYPE ~= nil then
72 print('Content-type: ' .. env.CONTENT_TYPE .. '<br>')
73 end
75 for k, v in pairs(query) do
76 print(k .. '=' .. v .. '<br/>')
77 end
78 else
79 print('No values')
80 end
81 end
83 -- register this handler for http://<hostname>/<prefix>/printenv
84 httpd.register_handler('printenv', printenv)
85 httpd.register_handler('form', form)