下面的代码在 Openresty lua 中运行良好
ngx.header["Set-Cookie"] = {
'test1=; expires=Thu, Jan 01 1970 00:00:00 UTC; domain=test.com;',
'test2=; expires=Thu, Jan 01 1970 00:00:00 UTC; domain=test.com;'
}
虽然在尝试使 cookie 名称动态化时,它不起作用:
local cookies = {}
local args = {'test1', 'test2'}
for i=1, #args do
cookies[i] = args[i] .. '=; expires=Thu, Jan 01 1970 00:00:00 UTC; domain=test.com;'
end
ngx.header["Set-Cookie"] = cookies
甚至尝试过使用 table.insert:
local cookies = {}
local args = {'test1', 'test2'}
for i=1, #args do
table.insert(cookies, args[i] .. '=; expires=Thu, Jan 01 1970 00:00:00 UTC; domain=test.com;')
end
ngx.header["Set-Cookie"] = cookies
问题似乎与变量的分配ngx.header["Set-Cookie"]