Skip to content

Commit

Permalink
fix(ext-plugin): avoid using 0 as the default http status code (#4734)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzssangglass authored Aug 3, 2021
1 parent 8e72f3e commit 316d230
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 6 additions & 1 deletion apisix/plugins/ext-plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ local rpc_handlers = {
end
body = ffi_str(body, len)
end
return true, nil, stop:Status(), body
local code = stop:Status()
-- avoid using 0 as the default http status code
if code == 0 then
code = 200
end
return true, nil, code, body
end

if action_type == http_req_call_action.Rewrite then
Expand Down
4 changes: 3 additions & 1 deletion t/lib/ext-plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ function _M.go(case)
local vec = builder:EndVector(len)

http_req_call_stop.Start(builder)
http_req_call_stop.AddStatus(builder, 405)
if case.check_default_status ~= true then
http_req_call_stop.AddStatus(builder, 405)
end
http_req_call_stop.AddBody(builder, b)
http_req_call_stop.AddHeaders(builder, vec)
local action = http_req_call_stop.End(builder)
Expand Down
20 changes: 20 additions & 0 deletions t/plugin/ext-plugin/http-req-call.t
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,23 @@ GET /hello
--- access_log
GET /plugin_proxy_rewrite_args%3Fa=2
--- error_code: 404
=== TEST 18: stop without setting status code
--- request
GET /hello
--- response_body chomp
cat
--- extra_stream_config
server {
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
content_by_lua_block {
local ext = require("lib.ext-plugin")
ext.go({stop = true, check_default_status = true})
}
}
--- response_headers
X-Resp: foo
X-Req: bar

0 comments on commit 316d230

Please sign in to comment.