Skip to content

Commit

Permalink
do not override already set content-type, fixes koajs#1120
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0w committed Feb 2, 2018
1 parent a64e4ae commit c7b620a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = {

// json
this.remove('Content-Length');
this.type = 'json';
if (setType) this.type = 'json';
},

/**
Expand Down
4 changes: 2 additions & 2 deletions test/response/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ describe('res.body=', () => {
});

describe('when body is an object', () => {
it('should override as json', () => {
it('should not override as json', () => {
const res = response();

res.body = '<em>hey</em>';
assert.equal('text/html; charset=utf-8', res.header['content-type']);

res.body = { foo: 'bar' };
assert.equal('application/json; charset=utf-8', res.header['content-type']);
assert.equal('text/html; charset=utf-8', res.header['content-type']);
});
});

Expand Down

0 comments on commit c7b620a

Please sign in to comment.