diff --git a/lib/application.js b/lib/application.js index 5ebe179a2..d10245fb5 100644 --- a/lib/application.js +++ b/lib/application.js @@ -257,7 +257,7 @@ function respond(ctx) { // allow bypassing koa if (false === ctx.respond) return; - if (!ctx.writable) return; + if (!ctx.writable) return ctx.res.end(); const res = ctx.res; let body = ctx.body; @@ -267,7 +267,7 @@ function respond(ctx) { if (statuses.empty[code]) { // strip headers ctx.body = null; - return res.end(); + return ctx.res.end(); } if ('HEAD' === ctx.method) { @@ -275,7 +275,7 @@ function respond(ctx) { const { length } = ctx.response; if (Number.isInteger(length)) ctx.length = length; } - return res.end(); + return ctx.res.end(); } // status body @@ -283,7 +283,7 @@ function respond(ctx) { if (ctx.response._explicitNullBody) { ctx.response.remove('Content-Type'); ctx.response.remove('Transfer-Encoding'); - return res.end(); + return ctx.res.end(); } if (ctx.req.httpVersionMajor >= 2) { body = String(code);