diff --git a/apisix/plugins/response-rewrite.lua b/apisix/plugins/response-rewrite.lua index c07924253eb9..4c3487da0686 100644 --- a/apisix/plugins/response-rewrite.lua +++ b/apisix/plugins/response-rewrite.lua @@ -276,14 +276,12 @@ function _M.body_filter(conf, ctx) end if conf.body then - + ngx.arg[2] = true if conf.body_base64 then ngx.arg[1] = ngx.decode_base64(conf.body) else ngx.arg[1] = conf.body end - - ngx.arg[2] = true end end diff --git a/t/plugin/response-rewrite.t b/t/plugin/response-rewrite.t index 53b3d1d10d80..d9283e3fe7d9 100644 --- a/t/plugin/response-rewrite.t +++ b/t/plugin/response-rewrite.t @@ -699,3 +699,50 @@ X-A: 127.0.0.1 X-B: from 127.0.0.1 to 127.0.0.1:1980 --- no_error_log [error] + + + +=== TEST 25: set empty body +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "response-rewrite": { + "body": "" + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 26: hit set empty body +--- request +GET /hello +--- response_body +--- no_error_log +[error]