From 316d23074f725e3d27d785c272cbde85de549831 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Tue, 3 Aug 2021 10:15:17 +0800 Subject: [PATCH] fix(ext-plugin): avoid using 0 as the default http status code (#4734) --- apisix/plugins/ext-plugin/init.lua | 7 ++++++- t/lib/ext-plugin.lua | 4 +++- t/plugin/ext-plugin/http-req-call.t | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/ext-plugin/init.lua b/apisix/plugins/ext-plugin/init.lua index 8adb9ee2..e80006ad 100644 --- a/apisix/plugins/ext-plugin/init.lua +++ b/apisix/plugins/ext-plugin/init.lua @@ -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 diff --git a/t/lib/ext-plugin.lua b/t/lib/ext-plugin.lua index 3f0e616c..ee2f997f 100644 --- a/t/lib/ext-plugin.lua +++ b/t/lib/ext-plugin.lua @@ -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) diff --git a/t/plugin/ext-plugin/http-req-call.t b/t/plugin/ext-plugin/http-req-call.t index 6e6b0e37..5fc9ec23 100644 --- a/t/plugin/ext-plugin/http-req-call.t +++ b/t/plugin/ext-plugin/http-req-call.t @@ -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