view 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
line wrap: on
line source

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