annotate src/tools/cookies.html.luan @ 47:7ef9222474e2

add more button
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 14 Nov 2022 23:01:29 -0700
parents 2f20b11affdd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local pairs = Luan.pairs or error()
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Html = require "luan:Html.luan"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local html_encode = Html.encode or error()
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Logging = require "luan:logging/Logging.luan"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local logger = Logging.logger "cookies.html"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 return function()
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local name = Http.request.parameters.name
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 if name ~= nil then
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local value = Http.request.parameters.value
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local persistent = Http.request.parameters.persistent
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 if #value == 0 then
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 Http.response.remove_cookie(name)
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 elseif persistent ~= nil then
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 Http.response.set_persistent_cookie(name,value)
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 else
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Http.response.set_cookie(name,value)
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 Http.response.send_redirect "cookies.html"
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 Io.stdout = Http.response.text_writer()
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 %>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <!doctype html>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 <html>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <head>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <meta name="viewport" content="width=device-width, initial-scale=1">
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <style>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 form {
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 margin-bottom: 16px;
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 }
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 </style>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 </head>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <body>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <h2>Cookies Tool</h2>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <%
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 for name, value in pairs(Http.request.cookies) do
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 name = html_encode(name)
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 value = html_encode(value)
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 %>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <form>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <input name=name value="<%=name%>" type=hidden>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <%=name%> = <input name=value value="<%=value%>" size=100>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 <label><input type=checkbox name=persistent>persistent</label>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 </form>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <% end %>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 <form>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <input name=name>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 = <input name=value size=100>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 <label><input type=checkbox name=persistent>persistent</label>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 <input type=submit>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 </form>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 </body>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 </html>
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 <%
2f20b11affdd add tools
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 end