add overriding to application/json on ctx.body=object
since it cant be anything else, but if you have middleware that transforms the object to xml or something then you could set ctx.type=
This commit is contained in:
parent
c4d194488c
commit
3b2c55b68b
2 changed files with 14 additions and 2 deletions
|
@ -187,7 +187,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
// json
|
||||
if (setType) this.type = 'json';
|
||||
this.type = 'json';
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,11 +30,23 @@ describe('ctx.body=', function(){
|
|||
assert('image/png' == ctx.responseHeader['content-type']);
|
||||
})
|
||||
|
||||
describe('when body is an object', function(){
|
||||
it('should override as json', function(){
|
||||
var ctx = context();
|
||||
|
||||
ctx.body = '<em>hey</em>';
|
||||
assert('text/html; charset=utf-8' == ctx.responseHeader['content-type']);
|
||||
|
||||
ctx.body = { foo: 'bar' };
|
||||
assert('application/json' == ctx.responseHeader['content-type']);
|
||||
})
|
||||
})
|
||||
|
||||
it('should override length', function(){
|
||||
var ctx = context();
|
||||
ctx.type = 'html';
|
||||
ctx.body = 'something';
|
||||
assert.equal(ctx.responseLength, 9);
|
||||
ctx.responseLength.should.equal(9);
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue