From 42bbd754beb1fc0a6a0f7366bb3f20aef2ec8413 Mon Sep 17 00:00:00 2001 From: Jiale Zhi Date: Wed, 16 Jul 2014 16:53:35 -0700 Subject: Do not set cookie when it is duplicated --- t/sanity.t | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/sanity.t b/t/sanity.t index 1385ebb..952b81e 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -5,7 +5,7 @@ use Cwd qw(cwd); repeat_each(2); -plan tests => repeat_each() * (blocks() * 3 + 2); +plan tests => repeat_each() * (blocks() * 3 + 4); my $pwd = cwd(); @@ -257,3 +257,53 @@ key, so use "--- raw_response_headers_like" instead --- raw_response_headers_like: Set-Cookie: Name=Bob; Path=/\r\nSet-Cookie: Age=20\r\nSet-Cookie: ID=0xf7898; Expires=Wed, 09 Jun 2021 10:18:14 GMT --- response_body Set cookie + + + +=== TEST 8: remove duplicated cookies in cookie:set +--- http_config eval: $::HttpConfig +--- config + location /t { + content_by_lua ' + local ck = require "resty.cookie" + local cookie, err = ck:new() + if not cookie then + ngx.log(ngx.ERR, err) + return + end + + local ok, err = cookie:set({ + key = "Name", value = "Bob", path = "/", + }) + if not ok then + ngx.log(ngx.ERR, err) + return + end + + local ok, err = cookie:set({ + key = "Age", value = "20", + }) + if not ok then + ngx.log(ngx.ERR, err) + return + end + + local ok, err = cookie:set({ + key = "Name", value = "Bob", path = "/", + }) + if not ok then + ngx.log(ngx.ERR, err) + return + end + + ngx.say("Set cookie") + '; + } +--- request +GET /t +--- no_error_log +[error] +--- raw_response_headers_like: Set-Cookie: Name=Bob; Path=/\r\nSet-Cookie: Age=20\r\n +--- raw_response_headers_unlike: Set-Cookie: Name=Bob; Path=/\r\nSet-Cookie: Age=20\r\nSet-Cookie: Name=Bob; Path=/ +--- response_body +Set cookie -- cgit v1.2.3-54-g00ecf