cloudflare / lua-resty-cookie

Lua library for HTTP cookie manipulations for OpenResty/ngx_lua
347 stars 160 forks source link

bad argument #1 to 'clear_tab' (table expected, got nil) #24

Open ctessier opened 6 years ago

ctessier commented 6 years ago

Hi,

I am getting the following error when trying to set a new cookie: failed to run body_filter_by_lua*: /usr/local/share/lua/5.1/resty/cookie.lua:164: bad argument #1 to 'clear_tab' (table expected, got nil)

My code:

return cookie:set({
        key = "Name",
        value = "Bob",
        path = "/",
        domain = "domain.com",
        secure = false, httponly = true,
        expires = "Wed, 09 Jun 2021 10:18:14 GMT",
        max_age = 50,
        samesite = "Strict",
        extension = "a4334aebaec"
    })

Thank you for your help

miguel-martinez-tfs commented 4 years ago

Very late, but to anyone else who ran into this problem (like me), the solution is to initialize an instance first, like so:

local ck = require "resty.cookie"
local cookie, err = ck:new()
return cookie:set({
...