[BACK]Return to printenv.lua CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / libexec / httpd

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/libexec/httpd/printenv.lua between version 1.2.12.2 and 1.3

version 1.2.12.2, 2014/07/09 15:21:21 version 1.3, 2015/12/07 03:11:48
Line 8 
Line 8 
 -- the same value on each invocation.  You can not keep state between  -- the same value on each invocation.  You can not keep state between
 -- two calls.  -- 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'  local httpd = require 'httpd'
   
 function printenv(env, headers, query)  function printenv(env, headers, query)
Line 15  function printenv(env, headers, query)
Line 19  function printenv(env, headers, query)
         -- we get the "environment" in the env table, the values are more          -- we get the "environment" in the env table, the values are more
         -- or less the same as the variable for a CGI program          -- or less the same as the variable for a CGI program
   
         if count == nil then          -- output headers using httpd.write()
                 count = 1          -- httpd.write() will not append newlines
         end          httpd.write("HTTP/1.1 200 Ok\r\n")
           httpd.write("Content-Type: text/html\r\n\r\n")
         -- output a header  
         print([[          -- output html using httpd.print()
           -- you can also use print() and io.write() but they will not work with SSL
           httpd.print([[
                 <html>                  <html>
                         <head>                          <head>
                                 <title>Bozotic Lua Environment</title>                                  <title>Bozotic Lua Environment</title>
Line 29  function printenv(env, headers, query)
Line 35  function printenv(env, headers, query)
                                 <h1>Bozotic Lua Environment</h1>                                  <h1>Bozotic Lua Environment</h1>
         ]])          ]])
   
         print('module version: ' .. httpd._VERSION .. '<br>')          httpd.print('module version: ' .. httpd._VERSION .. '<br>')
   
         print('<h2>Server Environment</h2>')          httpd.print('<h2>Server Environment</h2>')
         -- print the list of "environment" variables          -- print the list of "environment" variables
         for k, v in pairs(env) do          for k, v in pairs(env) do
                 print(k .. '=' .. v .. '<br/>')                  httpd.print(k .. '=' .. v .. '<br/>')
         end          end
   
         print('<h2>Request Headers</h2>')          httpd.print('<h2>Request Headers</h2>')
         for k, v in pairs(headers) do          for k, v in pairs(headers) do
                 print(k .. '=' .. v .. '<br/>')                  httpd.print(k .. '=' .. v .. '<br/>')
         end          end
   
         if query ~= nil then          if query ~= nil then
                 print('<h2>Query Variables</h2>')                  httpd.print('<h2>Query Variables</h2>')
                 for k, v in pairs(query) do                  for k, v in pairs(query) do
                         print(k .. '=' .. v .. '<br/>')                          httpd.print(k .. '=' .. v .. '<br/>')
                 end                  end
         end          end
   
         print('<h2>Form Test</h2>')          httpd.print('<h2>Form Test</h2>')
   
         print([[          httpd.print([[
         <form method="POST" action="/rest/form?sender=me">          <form method="POST" action="form?sender=me">
         <input type="text" name="a_value">          <input type="text" name="a_value">
         <input type="submit">          <input type="submit">
         </form>          </form>
         ]])          ]])
         -- output a footer          -- output a footer
         print([[          httpd.print([[
                 </body>                  </body>
         </html>          </html>
         ]])          ]])
 end  end
   
 function form(env, header, query)  function form(env, header, query)
   
           httpd.write("HTTP/1.1 200 Ok\r\n")
           httpd.write("Content-Type: text/html\r\n\r\n")
   
         if query ~= nil then          if query ~= nil then
                 print('<h2>Form Variables</h2>')                  httpd.print('<h2>Form Variables</h2>')
   
                 if env.CONTENT_TYPE ~= nil then                  if env.CONTENT_TYPE ~= nil then
                         print('Content-type: ' .. env.CONTENT_TYPE .. '<br>')                          httpd.print('Content-type: ' .. env.CONTENT_TYPE .. '<br>')
                 end                  end
   
                 for k, v in pairs(query) do                  for k, v in pairs(query) do
                         print(k .. '=' .. v .. '<br/>')                          httpd.print(k .. '=' .. v .. '<br/>')
                 end                  end
         else          else
                 print('No values')                  httpd.print('No values')
         end          end
 end  end
   

Legend:
Removed from v.1.2.12.2  
changed lines
  Added in v.1.3

CVSweb <webmaster@jp.NetBSD.org>