fix ctx.body= content-type override check. Thanks @jonathanong

This commit is contained in:
TJ Holowaychuk 2013-09-15 08:51:56 -07:00
parent 11913f5e4e
commit 83fd83aaf8
2 changed files with 12 additions and 2 deletions

View File

@ -153,8 +153,6 @@ module.exports = {
set body(val) {
this._body = val;
if (this.type) return;
// no content
if (null == val) {
var s = this.status;
@ -165,6 +163,9 @@ module.exports = {
return;
}
// content-type already set
if (this.responseHeader['content-type']) return;
// string
if ('string' == typeof val) {
this.type = ~val.indexOf('<') ? 'html' : 'text';

View File

@ -22,6 +22,15 @@ function context(req, res) {
}
describe('ctx.body=', function(){
describe('when Content-Type is set', function(){
it('should not override', function(){
var ctx = context();
ctx.type = 'png';
ctx.body = new Buffer('something');
assert('image/png' == ctx.responseHeader['content-type']);
})
})
describe('when a string is given', function(){
it('should default to text', function(){
var ctx = context();