From 1dd9fb662e14723fd171806915abf5198fc3983f Mon Sep 17 00:00:00 2001 From: the lemons Date: Mon, 7 Feb 2022 14:53:56 -0600 Subject: add #unset --- zzcxz.cgi | 18 +++++++++++++++--- 1 file 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 { -- cgit v1.2.3