diff --git a/lib/response.js b/lib/response.js index f965e539dd2..bc2bc6fb438 100644 --- a/lib/response.js +++ b/lib/response.js @@ -673,7 +673,7 @@ res.header = function header(field, val) { if (Array.isArray(value)) { throw new TypeError('Content-Type cannot be set to an Array'); } - value = mime.contentType(value) + value = mime.contentType(value) || value } this.setHeader(field, value); diff --git a/test/res.set.js b/test/res.set.js index 04511c1c95f..de9cbff00dc 100644 --- a/test/res.set.js +++ b/test/res.set.js @@ -31,6 +31,34 @@ describe('res', function(){ .expect('X-Number', '123') .expect(200, 'string', done); }) + + it('should preserve unknown Content-Type shorthand', function (done) { + var app = express(); + + app.use(function (req, res) { + res.set('Content-Type', 'custom-type'); + res.end(); + }); + + request(app) + .get('/') + .expect('Content-Type', 'custom-type') + .expect(200, done); + }) + + it('should set Content-Type with valid full MIME type', function (done) { + var app = express(); + + app.use(function (req, res) { + res.set('Content-Type', 'application/x-custom'); + res.end(); + }); + + request(app) + .get('/') + .expect('Content-Type', 'application/x-custom') + .expect(200, done); + }) }) describe('.set(field, values)', function(){