From b24919f5ea1acc0c464d626b404ee412db0c9344 Mon Sep 17 00:00:00 2001 From: Liu Peng Date: Wed, 7 Jul 2021 14:51:25 +0800 Subject: [PATCH 1/2] fix: ctx.var.cookie_* cookie not found log --- apisix/core/ctx.lua | 8 ++++++-- t/core/ctx.t | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apisix/core/ctx.lua b/apisix/core/ctx.lua index 40181805c02d..aabf8a517684 100644 --- a/apisix/core/ctx.lua +++ b/apisix/core/ctx.lua @@ -111,7 +111,11 @@ end do local var_methods = { method = ngx.req.get_method, - cookie = function () return ck:new() end + cookie = function () + if ngx.var.http_cookie then + return ck:new() + end + end } local ngx_var_names = { @@ -153,7 +157,7 @@ do if cookie then local err val, err = cookie:get(sub_str(key, 8)) - if not val then + if err then log.warn("failed to fetch cookie value by key: ", key, " error: ", err) end diff --git a/t/core/ctx.t b/t/core/ctx.t index 8ea20226b396..5c015c51cdd8 100644 --- a/t/core/ctx.t +++ b/t/core/ctx.t @@ -83,8 +83,8 @@ arg_a: aaa GET /t?a=aaa --- response_body cookie_host: nil ---- error_log -failed to fetch cookie value by key: cookie_host error: no cookie found in the current request +--- no_error_log +[error] From 0688859ac6cef51c01eae858a6b0602c8b759cab Mon Sep 17 00:00:00 2001 From: Liu Peng Date: Fri, 9 Jul 2021 15:01:07 +0800 Subject: [PATCH 2/2] Update t/core/ctx.t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 罗泽轩 --- t/core/ctx.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/core/ctx.t b/t/core/ctx.t index 5c015c51cdd8..9a2413b6a28b 100644 --- a/t/core/ctx.t +++ b/t/core/ctx.t @@ -84,7 +84,7 @@ GET /t?a=aaa --- response_body cookie_host: nil --- no_error_log -[error] +failed to fetch cookie value by key