From 1a32ecac31d6d051d729b4c9befa0d9ee51a01ec Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Fri, 6 Jun 2014 16:26:03 -0700 Subject: [PATCH] fix res.type= for unknown types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit because we changed from mime to mime-types. ideally, we should just not set the content-type, but this way it’s backwards compatible. we can change it later. --- lib/response.js | 2 +- test/response/type.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index 5ef6708..892f430 100644 --- a/lib/response.js +++ b/lib/response.js @@ -274,7 +274,7 @@ module.exports = { */ set type(type) { - this.set('Content-Type', getType(type)); + this.set('Content-Type', getType(type) || 'application/octet-stream'); }, /** diff --git a/test/response/type.js b/test/response/type.js index 1897d87..6fc65b4 100644 --- a/test/response/type.js +++ b/test/response/type.js @@ -38,6 +38,15 @@ describe('ctx.type=', function(){ ctx.response.header['content-type'].should.equal('text/html; charset=foo'); }) }) + + describe('with an unknown extension', function(){ + it('should default to application/octet-stream',function(){ + var ctx = context(); + ctx.type = 'asdf'; + ctx.type.should.equal('application/octet-stream'); + ctx.response.header['content-type'].should.equal('application/octet-stream'); + }) + }) }) describe('ctx.type', function(){