parent
406a2966ca
commit
de20a5c96c
3 changed files with 34 additions and 7 deletions
|
@ -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');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(){
|
||||
|
|
Loading…
Reference in a new issue