fix(ext-plugin): avoid using 0 as the default http status code (#4734)

This commit is contained in:
tzssangglass 2021-08-03 10:15:17 +08:00 committed by GitHub
parent 8e72f3e718
commit 316d23074f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -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