diff --git a/lib/response.js b/lib/response.js index ad6c2a1f..53665b8c 100644 --- a/lib/response.js +++ b/lib/response.js @@ -340,7 +340,8 @@ res.respondTo = function(obj){ if (!accepted.length) key = keys.shift(); if (key) { - obj[key](req, res, next); + this.set('Content-Type', key); + obj[key](req, this, next); } else { var err = new Error('Not Acceptable'); err.status = 406; diff --git a/test/res.respondTo.js b/test/res.respondTo.js index 63d1338e..e8743b36 100644 --- a/test/res.respondTo.js +++ b/test/res.respondTo.js @@ -8,7 +8,7 @@ var app = express(); app.use(function(req, res, next){ res.respondTo({ 'text/plain': function(){ - res.type('text').send('hey'); + res.send('hey'); }, 'text/html': function(){ @@ -41,6 +41,17 @@ describe('req', function(){ .expect('{"message":"hey"}', done); }) + it('should default the Content-Type', function(done){ + request(app) + .get('/') + .set('Accept', 'text/html; q=.5, text/plain') + .end(function(res){ + res.headers['content-type'].should.equal('text/plain'); + res.body.should.equal('hey'); + done(); + }); + }) + describe('when Accept is not present', function(){ it('should invoke the first callback', function(done){ request(app)