Added lot more example code. (0.39.8).
This commit is contained in:
parent
3b70d6c92a
commit
564999709c
32 changed files with 1353 additions and 53 deletions
31
examples/data/htdocs/counter.fun
Normal file
31
examples/data/htdocs/counter.fun
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2026 Johannes Findeisen
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-03-25
|
||||
*/
|
||||
|
||||
#include <net/cgi.fun>
|
||||
|
||||
cgi = CGI()
|
||||
v = to_number(cgi.cookie("visits"))
|
||||
if (v <= 0) v = 0
|
||||
v = v + 1
|
||||
cgi.header("Set-Cookie", "visits=" + to_string(v) + "; Path=/; HttpOnly")
|
||||
cgi.content_type("text/html; charset=utf-8")
|
||||
body = "<html><body><p>Visits: " + to_string(v) + "</p></body></html>"
|
||||
cgi.send(body)
|
||||
|
||||
/* Expected output (first visit, no existing cookie):
|
||||
Status: 200 OK
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Set-Cookie: visits=1; Path=/; HttpOnly
|
||||
|
||||
<html><body><p>Visits: 1</p></body></html>
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue