diff --git a/lib/response.js b/lib/response.js index c2cd7c8..8027c19 100644 --- a/lib/response.js +++ b/lib/response.js @@ -301,7 +301,12 @@ module.exports = { */ set type(type) { - this.set('Content-Type', getType(type) || 'application/octet-stream'); + type = getType(type) || false; + if (type) { + this.set('Content-Type', type); + } else { + this.remove('Content-Type'); + } }, /** diff --git a/test/application.js b/test/application.js index 2494e0e..91bfade 100644 --- a/test/application.js +++ b/test/application.js @@ -237,6 +237,28 @@ describe('app.respond', function(){ }) }) + describe('when this.type === null', function(){ + it('should not send Content-Type header', function(done){ + var app = koa(); + + app.use(function *(){ + this.body = ''; + this.type = null; + }); + + var server = app.listen(); + + request(server) + .get('/') + .expect(200) + .end(function(err, res){ + if (err) return done(err); + res.should.not.have.header('content-type'); + done(); + }); + }); + }); + describe('when HEAD is used', function(){ it('should not respond with the body', function(done){ var app = koa(); diff --git a/test/response/type.js b/test/response/type.js index a02e248..eaa7f52 100644 --- a/test/response/type.js +++ b/test/response/type.js @@ -42,14 +42,14 @@ describe('ctx.type=', function(){ }) describe('with an unknown extension', function(){ - it('should default to application/octet-stream',function(){ + it('should not set a content-type', function(){ var ctx = context(); ctx.type = 'asdf'; - ctx.type.should.equal('application/octet-stream'); - ctx.response.header['content-type'].should.equal('application/octet-stream'); - }) - }) -}) + assert(!ctx.type); + assert(!ctx.response.header['content-type']); + }); + }); +}); describe('ctx.type', function(){ describe('with no Content-Type', function(){