diff options
author | Jiale Zhi <vipcalio@gmail.com> | 2014-07-16 16:53:35 -0700 |
---|---|---|
committer | Jiale Zhi <vipcalio@gmail.com> | 2014-07-16 16:53:35 -0700 |
commit | 42bbd754beb1fc0a6a0f7366bb3f20aef2ec8413 (patch) | |
tree | dfe99b6257d05aa3d3d8e93965044f8390d5219d /lib | |
parent | 906de6fdb5025b6481926b9066151fd399c9870c (diff) | |
download | lua-resty-cookie-42bbd754beb1fc0a6a0f7366bb3f20aef2ec8413.tar.gz lua-resty-cookie-42bbd754beb1fc0a6a0f7366bb3f20aef2ec8413.tar.bz2 lua-resty-cookie-42bbd754beb1fc0a6a0f7366bb3f20aef2ec8413.zip |
Do not set cookie when it is duplicated
Diffstat (limited to 'lib')
-rw-r--r-- | lib/resty/cookie.lua | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/resty/cookie.lua b/lib/resty/cookie.lua index a96da60..dfb8f8a 100644 --- a/lib/resty/cookie.lua +++ b/lib/resty/cookie.lua @@ -165,9 +165,11 @@ function _M.set(self, cookie) if set_cookie_type == "string" then -- only one cookie has been setted - t[1] = set_cookie - t[2] = cookie_str - ngx_header['Set-Cookie'] = t + if set_cookie ~= cookie_str then + t[1] = set_cookie + t[2] = cookie_str + ngx_header['Set-Cookie'] = t + end elseif set_cookie_type == "table" then -- more than one cookies has been setted local size = #set_cookie @@ -176,6 +178,10 @@ function _M.set(self, cookie) -- so create a new table, copy all the values, and then set it back for i=1, size do t[i] = ngx_header['Set-Cookie'][i] + if t[i] == cookie_str then + -- new cookie is duplicated + return true + end end t[size + 1] = cookie_str ngx_header['Set-Cookie'] = t |