From 325418424ec6f157c984701043a003d6b46d6827 Mon Sep 17 00:00:00 2001 From: Eladio Mora Date: Sun, 19 Apr 2020 22:33:02 -0300 Subject: [PATCH] feat: allow bodyless responses for non empty status codes --- lib/application.js | 5 +++++ lib/response.js | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/application.js b/lib/application.js index 57b701cef..ab711d294 100644 --- a/lib/application.js +++ b/lib/application.js @@ -238,6 +238,11 @@ function respond(ctx) { // status body if (null == body) { + if (ctx.response._explicitNullBody) { + ctx.response.remove('Content-Type'); + ctx.response.remove('Transfer-Encoding'); + return res.end(); + } if (ctx.req.httpVersionMajor >= 2) { body = String(code); } else { diff --git a/lib/response.js b/lib/response.js index 87ecc56a9..4f2fc2783 100644 --- a/lib/response.js +++ b/lib/response.js @@ -139,6 +139,7 @@ module.exports = { // no content if (null == val) { if (!statuses.empty[this.status]) this.status = 204; + this._explicitNullBody = true; this.remove('Content-Type'); this.remove('Content-Length'); this.remove('Transfer-Encoding');