aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-02-07 14:53:56 -0600
committerthe lemons <citrons@mondecitronne.com>2022-02-07 14:53:56 -0600
commit1dd9fb662e14723fd171806915abf5198fc3983f (patch)
tree160ff33564aa85f0904a1f50984f737d52047def
parent870ccb5124109afadb42691efea8cb727cbde326 (diff)
add #unset
-rwxr-xr-xzzcxz.cgi18
1 files changed, 15 insertions, 3 deletions
diff --git a/zzcxz.cgi b/zzcxz.cgi
index 7fa53ee..c6c8de4 100755
--- a/zzcxz.cgi
+++ b/zzcxz.cgi
@@ -176,6 +176,11 @@ local function parse_directive(line, directives)
if utf8.len(flagname) > 150 then return end
directives.flags_updated[flagname] = text
flags[flagname] = text
+ elseif directive == "unset" then
+ local flagname = args:match "^%s*(%w+)%s*$"
+ if not flagname then return end
+ directives.flags_updated[flagname] = false
+ flags[flagname] = nil
else
return
end
@@ -343,9 +348,16 @@ map["^/g/(%w%w%w%w%w)$"] = function(p)
local cookies = {}
for flagname, text in pairs(directives.flags_updated) do
- table.insert(cookies,
- ('flag_%s=%s; Secure; Max-Age=999999999')
- :format(flagname, url_encode(text)))
+ if text then
+ table.insert(cookies,
+ ('flag_%s=%s; secure; max-age=999999999999')
+ :format(flagname, url_encode(text)))
+ else
+ -- clear the cookie by expiring it in the past
+ table.insert(cookies,
+ ('flag_%s=; expires=Thu, 01 Jan 1970 00:00:00 GMT;')
+ :format(flagname))
+ end
end
return base {