diff --git a/docs/api.md b/docs/api.md index 8656309..1b982c1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -192,6 +192,10 @@ app.context({ if you have a typo an error will be thrown, displaying this list so you can make a correction. +### ctx.hasContent + + When the response status is __204__ or __304__ this returns __false__. + ### ctx.length Return request Content-Length as a number when present, or undefined. diff --git a/lib/context.js b/lib/context.js index 15f7719..a2d3c61 100644 --- a/lib/context.js +++ b/lib/context.js @@ -71,13 +71,26 @@ module.exports = { val = n; } - if (204 == val || 304 == val) { + this.res.statusCode = val; + + if (!this.hasContent) { this.res.removeHeader('Content-Type'); this.res.removeHeader('Content-Length'); this.res.removeHeader('Transfer-Encoding'); } + }, - this.res.statusCode = val; + /** + * Check if the response has content, + * aka is not a 204 or 304 response. + * + * @return {Boolean} + * @api public + */ + + get hasContent() { + var s = this.status; + return 204 != s && 304 != s; }, /**