Hello!
On Tue, Jan 12, 2016 at 3:27 AM, Apoorv Saxena wrote:
> though when trying to make the cookie names dynamic, it doesn't work:
>
>
> 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
>
Your example works for me with the following minimal configuration:
location = /t {
content_by_lua_block {
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
}
}
Querying /t using curl:
$ curl -i localhost:8080/t
HTTP/1.1 200 OK
Server: nginx/1.9.7
Date: Tue, 12 Jan 2016 20:00:40 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: test1=; expires=Thu, Jan 01 1970 00:00:00 UTC; domain=test.com;
Set-Cookie: test2=; expires=Thu, Jan 01 1970 00:00:00 UTC; domain=test.com;
Maybe your OpenResty or ngx_lua is just too old? You can try the
latest OpenResty 1.9.7.2 RC1 version on your side.
Best regards,
-agentzh