remove .status=string #298
This commit is contained in:
parent
1f908137d2
commit
c2322f2b3d
2 changed files with 23 additions and 18 deletions
|
@ -13,6 +13,7 @@ var destroy = require('dethroy');
|
|||
var http = require('http');
|
||||
var path = require('path');
|
||||
var vary = require('vary');
|
||||
var assert = require('assert');
|
||||
var basename = path.basename;
|
||||
var extname = path.extname;
|
||||
|
||||
|
@ -71,14 +72,17 @@ module.exports = {
|
|||
/**
|
||||
* Set response status code.
|
||||
*
|
||||
* @param {Number|String} code
|
||||
* @param {Number} code
|
||||
* @api public
|
||||
*/
|
||||
|
||||
set status(code) {
|
||||
if ('number' != typeof code) code = status(code);
|
||||
assert(typeof code === 'number', 'status code must be a number');
|
||||
if(!http.STATUS_CODES[code]) throw new Error('invalid status code: ' + code);
|
||||
|
||||
this._explicitStatus = true;
|
||||
this.res.statusCode = code;
|
||||
|
||||
if (this.body && status.empty[code]) this.body = null;
|
||||
},
|
||||
|
||||
|
|
|
@ -5,37 +5,38 @@ var assert = require('assert');
|
|||
var koa = require('../..');
|
||||
|
||||
describe('res.status=', function(){
|
||||
describe('when a status string', function(){
|
||||
describe('when a status code', function(){
|
||||
describe('and valid', function(){
|
||||
it('should set the status', function(){
|
||||
var res = response();
|
||||
res.status = 'forbidden';
|
||||
res.status = 403;
|
||||
res.status.should.equal(403);
|
||||
})
|
||||
|
||||
it('should be case-insensitive', function(){
|
||||
var res = response();
|
||||
res.status = 'ForBidden';
|
||||
res.status.should.equal(403);
|
||||
it('should not throw', function(){
|
||||
assert.doesNotThrow(function() {
|
||||
response().status = 403;
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
describe('and invalid', function(){
|
||||
it('should throw', function(){
|
||||
var res = response();
|
||||
var err;
|
||||
|
||||
try {
|
||||
res.status = 'maru';
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
assert(err);
|
||||
assert.throws(function() {
|
||||
response().status = 999;
|
||||
}, 'invalid status code: 999');
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a status string', function(){
|
||||
it('should throw', function(){
|
||||
assert.throws(function() {
|
||||
response().status = 'forbidden';
|
||||
}, 'status code must be a number');
|
||||
})
|
||||
})
|
||||
|
||||
function strip(status) {
|
||||
it('should strip content related header fields', function(done){
|
||||
var app = koa();
|
||||
|
|
Loading…
Reference in a new issue