mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-04 13:07:34 +08:00
bugfix: maybe missing body when calling response.exit
.
This commit is contained in:
parent
6ab1dcde81
commit
3cf18bb4eb
@ -31,6 +31,10 @@ end
|
||||
|
||||
local function run_plugin(phase, filter_plugins, api_ctx)
|
||||
api_ctx = api_ctx or ngx.ctx.api_ctx
|
||||
if not api_ctx then
|
||||
return
|
||||
end
|
||||
|
||||
filter_plugins = filter_plugins or api_ctx.filter_plugins
|
||||
if not filter_plugins then
|
||||
return
|
||||
@ -66,7 +70,7 @@ function _M.rewrite_phase()
|
||||
local ok = router():dispatch(method, uri, api_ctx)
|
||||
if not ok then
|
||||
core.log.warn("not find any matched route")
|
||||
return core.response.say(404)
|
||||
return core.response.exit(404)
|
||||
end
|
||||
|
||||
local local_plugins = core.lrucache.global("/local_plugins", nil,
|
||||
@ -103,7 +107,7 @@ end
|
||||
|
||||
function _M.balancer_phase()
|
||||
local api_ctx = ngx.ctx.api_ctx
|
||||
if not api_ctx.filter_plugins then
|
||||
if not api_ctx or not api_ctx.filter_plugins then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -9,7 +9,6 @@ local select = select
|
||||
local type = type
|
||||
local ngx_exit = ngx.exit
|
||||
local insert_tab = table.insert
|
||||
local clear_tab = table.clear
|
||||
local concat_tab = table.concat
|
||||
|
||||
|
||||
@ -19,9 +18,10 @@ local _M = {version = 0.1}
|
||||
local resp_exit
|
||||
do
|
||||
local t = {}
|
||||
local idx = 1
|
||||
|
||||
function resp_exit(code, ...)
|
||||
clear_tab(t)
|
||||
idx = 0
|
||||
|
||||
if type(code) ~= "number" then
|
||||
insert_tab(t, code)
|
||||
@ -39,15 +39,19 @@ function resp_exit(code, ...)
|
||||
if err then
|
||||
error("failed to encode data: " .. err, -2)
|
||||
else
|
||||
insert_tab(t, body)
|
||||
idx = idx + 1
|
||||
insert_tab(t, idx, body)
|
||||
end
|
||||
|
||||
else
|
||||
insert_tab(t, v)
|
||||
idx = idx + 1
|
||||
insert_tab(t, idx, v)
|
||||
end
|
||||
end
|
||||
|
||||
ngx_say(concat_tab(t))
|
||||
if idx > 0 then
|
||||
ngx_say(concat_tab(t, "", 1, idx))
|
||||
end
|
||||
|
||||
if code then
|
||||
ngx_exit(code)
|
||||
|
@ -36,8 +36,7 @@ end
|
||||
|
||||
function _M.access(conf, ctx)
|
||||
core.log.warn("plugin access phase, conf: ", core.json.encode(conf))
|
||||
-- core.log.warn(" ctx: ", core.json.encode(ctx, true))
|
||||
ngx.say("hit example plugin")
|
||||
-- return 200, {message = "hit example plugin"}
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user