Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ctx.var.cookie_* cookie not found log #4564

Merged
merged 2 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions t/core/ctx.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
failed to fetch cookie value by key



Expand Down