add Context#hasContent
This commit is contained in:
parent
f7b8b2b6ae
commit
b047405cc5
2 changed files with 19 additions and 2 deletions
|
@ -192,6 +192,10 @@ app.context({
|
||||||
if you have a typo an error will be thrown, displaying this list
|
if you have a typo an error will be thrown, displaying this list
|
||||||
so you can make a correction.
|
so you can make a correction.
|
||||||
|
|
||||||
|
### ctx.hasContent
|
||||||
|
|
||||||
|
When the response status is __204__ or __304__ this returns __false__.
|
||||||
|
|
||||||
### ctx.length
|
### ctx.length
|
||||||
|
|
||||||
Return request Content-Length as a number when present, or undefined.
|
Return request Content-Length as a number when present, or undefined.
|
||||||
|
|
|
@ -71,13 +71,26 @@ module.exports = {
|
||||||
val = n;
|
val = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (204 == val || 304 == val) {
|
this.res.statusCode = val;
|
||||||
|
|
||||||
|
if (!this.hasContent) {
|
||||||
this.res.removeHeader('Content-Type');
|
this.res.removeHeader('Content-Type');
|
||||||
this.res.removeHeader('Content-Length');
|
this.res.removeHeader('Content-Length');
|
||||||
this.res.removeHeader('Transfer-Encoding');
|
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;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue