diff src/tools/cookies.html.luan @ 5:2f20b11affdd

add tools
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 21 Jun 2022 21:39:27 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tools/cookies.html.luan	Tue Jun 21 21:39:27 2022 -0600
@@ -0,0 +1,62 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local pairs = Luan.pairs or error()
+local Html = require "luan:Html.luan"
+local html_encode = Html.encode or error()
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Logging = require "luan:logging/Logging.luan"
+local logger = Logging.logger "cookies.html"
+
+
+return function()
+	local name = Http.request.parameters.name
+	if name ~= nil then
+		local value = Http.request.parameters.value
+		local persistent = Http.request.parameters.persistent
+		if #value == 0 then
+			Http.response.remove_cookie(name)
+		elseif persistent ~= nil then
+			Http.response.set_persistent_cookie(name,value)
+		else
+			Http.response.set_cookie(name,value)
+		end
+		Http.response.send_redirect "cookies.html"
+		return
+	end
+
+	Io.stdout = Http.response.text_writer()
+%>
+<!doctype html>
+<html>
+	<head>
+		<meta name="viewport" content="width=device-width, initial-scale=1">
+		<style>
+			form {
+				margin-bottom: 16px;
+			}
+		</style>
+	</head>
+	<body>
+		<h2>Cookies Tool</h2>
+<%
+	for name, value in pairs(Http.request.cookies) do
+		name = html_encode(name)
+		value = html_encode(value)
+%>
+		<form>
+			<input name=name value="<%=name%>" type=hidden>
+			<%=name%> = <input name=value value="<%=value%>" size=100>
+			<label><input type=checkbox name=persistent>persistent</label>
+		</form>
+<%	end %>
+		<form>
+			<input name=name>
+			= <input name=value size=100>
+			<label><input type=checkbox name=persistent>persistent</label>
+			<input type=submit>
+		</form>
+	</body>
+</html>
+<%
+end