Some CGI Fun. (unstable) (0.39.5).
This commit is contained in:
parent
18ac230c21
commit
11d6fd358a
5 changed files with 769 additions and 44 deletions
28
examples/data/htdocs/hello.fun
Normal file
28
examples/data/htdocs/hello.fun
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
#include <net/cgi.fun>
|
||||
|
||||
cgi = CGI()
|
||||
|
||||
name = cgi.param("name")
|
||||
if (len(name) == 0)
|
||||
name = "World"
|
||||
|
||||
ua = cgi.cookie("ua")
|
||||
if (len(ua) == 0)
|
||||
// Set a demo cookie via header()
|
||||
cgi.header("Set-Cookie", "ua=FunClient; Path=/; HttpOnly")
|
||||
|
||||
cgi.content_type("text/html; charset=utf-8")
|
||||
|
||||
html = ""
|
||||
html = html + "<html><head><title>Fun CGI</title></head><body>"
|
||||
html = html + "<h1>Hello, " + cgi.escape_html(name) + "!</h1>"
|
||||
html = html + "<p>REQUEST_METHOD: " + cgi.escape_html(cgi.env["REQUEST_METHOD"]) + "</p>"
|
||||
html = html + "<p>QUERY_STRING: " + cgi.escape_html(cgi.env["QUERY_STRING"]) + "</p>"
|
||||
html = html + "<p>User-Agent cookie: " + cgi.escape_html(ua) + "</p>"
|
||||
html = html + "<h2>Params</h2><pre>" + to_string(cgi.params()) + "</pre>"
|
||||
html = html + "</body></html>"
|
||||
|
||||
// Send CGI headers + body
|
||||
cgi.send(html)
|
||||
Loading…
Add table
Add a link
Reference in a new issue