> Am 03.01.2016 um 23:23 schrieb Kamil Rytarowski <n...@gmx.com>:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> It's a good tip.
> 
> I would leave httpd.print as it is right now, to not make a false
> impression that there standard print works. The standard one will
> work, but not for HTTPS.

Oh, I was not suggesting you change the file again, I jsut wanted to note that 
a single line change would have been enough ;)

> 
> On 03.01.2016 11:15, Marc Balmer wrote:
>> Just a note: A better change would have been to just add
>> 
>> print = httpd.print
>> 
>> at the start of the script.  That way the script could still be 
>> used as a normal CGI script with minimal changes.
>> 
>> 
>>> Am 07.12.2015 um 04:11 schrieb Kamil Rytarowski 
>>> <ka...@netbsd.org>:
>>> 
>>> Module Name:        src Committed By:       kamil Date:             Mon Dec 
>>>  7 03:11:48 
>>> UTC 2015
>>> 
>>> Modified Files: src/libexec/httpd: printenv.lua
>>> 
>>> Log Message: Improve the httpd(8) printenv.lua Lua example
>>> 
>>> Stop using Lua builtin print function and replace them with 
>>> http.* ones. httpd.print and http.write wraps SSL support when 
>>> needed.
>>> 
>>> Print http headers, without them browser may interpret page as 
>>> raw text.
>>> 
>>> No need to hardcode prefix path in the form.
>>> 
>>> Add comments for a user with tips how to use this script.
>>> 
>>> Patch by Travis Paul
>>> 
>>> Closes PR misc/50502
>>> 
>>> 
>>> To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 
>>> src/libexec/httpd/printenv.lua
>>> 
>>> Please note that diffs are not public domain; they are subject
>>> to the copyright notices on the relevant files.
>>> 
>>> Modified files:
>>> 
>>> Index: src/libexec/httpd/printenv.lua diff -u 
>>> src/libexec/httpd/printenv.lua:1.2 
>>> src/libexec/httpd/printenv.lua:1.3 --- 
>>> src/libexec/httpd/printenv.lua:1.2  Thu Jan  2 08:21:38 2014 +++ 
>>> src/libexec/httpd/printenv.lua      Mon Dec  7 03:11:48 2015 @@ -1,4 
>>> +1,4 @@ --- $NetBSD: printenv.lua,v 1.2 2014/01/02 08:21:38 mrg 
>>> Exp $ +-- $NetBSD: printenv.lua,v 1.3 2015/12/07 03:11:48 kamil 
>>> 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([[ <html> <head> <title>Bozotic Lua
>>> Environment</title> @@ -29,54 +35,58 @@ function printenv(env,
>>> headers, query) <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 
>>> for k, v in pairs(env) do -         print(k .. '=' .. v .. '<br/>') + 
>>> httpd.print(k .. '=' .. v .. '<br/>') end
>>> 
>>> -   print('<h2>Request Headers</h2>') +     httpd.print('<h2>Request 
>>> Headers</h2>') for k, v in pairs(headers) do -              print(k .. '='
>>> .. v .. '<br/>') +          httpd.print(k .. '=' .. v .. '<br/>') end
>>> 
>>> if query ~= nil then -              print('<h2>Query Variables</h2>') + 
>>> httpd.print('<h2>Query Variables</h2>') for k, v in pairs(query) 
>>> do -                        print(k .. '=' .. v .. '<br/>') +               
>>>         httpd.print(k .. '=' 
>>> .. v .. '<br/>') end end
>>> 
>>> -   print('<h2>Form Test</h2>') +   httpd.print('<h2>Form 
>>> Test</h2>')
>>> 
>>> -   print([[ -      <form method="POST" action="/rest/form?sender=me">
>>> + httpd.print([[ +  <form method="POST" action="form?sender=me"> 
>>> <input type="text" name="a_value"> <input type="submit"> </form>
>>> ]]) -- output a footer -    print([[ +      httpd.print([[ </body> 
>>> </html> ]]) end
>>> 
>>> 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 -         print('<h2>Form Variables</h2>') + 
>>> httpd.print('<h2>Form Variables</h2>')
>>> 
>>> if env.CONTENT_TYPE ~= nil then -                   print('Content-type: ' 
>>> .. 
>>> env.CONTENT_TYPE .. '<br>') +                       
>>> httpd.print('Content-type: ' .. 
>>> env.CONTENT_TYPE .. '<br>') end
>>> 
>>> for k, v in pairs(query) do -                       print(k .. '=' .. v .. 
>>> '<br/>')
>>> + httpd.print(k .. '=' .. v .. '<br/>') end else -          print('No 
>>> values') +          httpd.print('No values') end end
>>> 
>>> 
>> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
> 
> iQIcBAEBCAAGBQJWiZ92AAoJEEuzCOmwLnZsTvEQAIlOctyuztNyZzhNdlCGEgYy
> qYsXvxwfkn/2hXg4V5T4z9DWUe+VTuhL76PXMfVL2S4r8Ticv9Uylpn7J4J5xGCq
> QkZNc2TevKOW8hjOhonsGKwNHP0uLs0NCFvJg8jAcntzDX9OltIPbxvtN3qYcpKs
> xeaaXhbSoUvk7nxldreI3/HmxTwxw/kBokfgu0KJMFeWY6qFIlUiKcXItiTAbqHE
> IHJYgSRm0DGSjlocJbuMBSG7nJ0OTuJcYUvCp4r3uaHwr09Q38HWJptQF8Xy1zxl
> ZJMGjlFwE/GMItbMoehQOaRydpYM3dpf7Oe9J2rLmOOCPD+agtz8uaF31WpWsgWr
> oxSTA9jmvHr2uei+P1Fz15v+71CAHGd76mndSjBMH54v2LdEVGo/1OLlABw/7Xon
> 3Yavu1437me4uhCAZMGVqH1IpYJDs04eGyYuCTG4aLkS3L+JCWE41Z5RztKWqR4N
> YmRxKGhUdLUVJuFYXTKsIoMejs52S7WNAPEs/xUa7Nae1GmvkiOeWqd5XraW9RK/
> a3im8COKXM/WyhFG4LkZTUT4KinBXnsUYP8jCs1xiwcY5IaxWXml1YXWUOGGgzTp
> ONKDN/UZcU90f9EzhqyUmNaB9tPDaZVnpAOXFWLkxmakLoGkW6nOrSteX2FDPZlL
> ZW0/tG+Q9CIW2GY2vIgi
> =agnW
> -----END PGP SIGNATURE-----

Reply via email to