Permalink
Browse files

add support for `res.json()` to retain previously defined Content-Typ…

…es. Closes #1349
  • Loading branch information...
1 parent 1029b0b commit 0d3a637389ce39646dfa8bd55708c4ac6b3640d6 @tj tj committed Sep 26, 2012
Showing with 19 additions and 1 deletion.
  1. +1 −1 lib/response.js
  2. +18 −0 test/res.json.js
View
@@ -190,7 +190,7 @@ res.json = function(obj){
// content-type
this.charset = this.charset || 'utf-8';
- this.set('Content-Type', 'application/json');
+ if (!this.get('Content-Type')) this.set('Content-Type', 'application/json');
return this.send(body);
};
View
@@ -163,4 +163,22 @@ describe('res', function(){
})
})
})
+
+ it('should not override previous Content-Types', function(done){
+ var app = express();
+
+ app.get('/', function(req, res){
+ res.type('application/vnd.example+json');
+ res.json({ hello: 'world' });
+ });
+
+ request(app)
+ .get('/')
+ .end(function(err, res){
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('content-type', 'application/vnd.example+json');
+ res.text.should.equal('{"hello":"world"}');
+ done();
+ })
+ })
})

0 comments on commit 0d3a637

Please sign in to comment.