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(){