app.respond: support 205 status codes as no-content

pretty new to me, but it’s basically the same as 204
master
Jonathan Ong 2013-11-19 22:20:17 -08:00
parent 16b016f61f
commit 1dd1d02db0
2 changed files with 102 additions and 14 deletions

View File

@ -180,7 +180,7 @@ function *respond(next){
var res = this.res;
var body = this.body;
var head = 'HEAD' == this.method;
var noContent = 204 == this.status || 304 == this.status;
var noContent = ~[204, 205, 304].indexOf(this.status);
// 404
if (null == body && 200 == this.status) {

View File

@ -104,6 +104,7 @@ describe('app.respond', function(){
})
describe('when .body is missing', function(){
describe('with status=400', function(){
it('should respond with the associated status message', function(done){
var app = koa();
@ -120,6 +121,93 @@ describe('app.respond', function(){
})
})
describe('with status=200', function(){
it('should respond with a 404', function(done){
var app = koa();
app.use(function *(){
this.status = 200;
})
var server = app.listen();
request(server)
.get('/')
.expect(404)
.expect('Not Found', done);
})
})
describe('with status=204', function(){
it('should respond without a body', function(done){
var app = koa();
app.use(function *(){
this.status = 204;
})
var server = app.listen();
request(server)
.get('/')
.expect(204)
.expect('')
.end(function (err, res) {
if (err) return done(err);
res.header.should.not.have.property('content-type');
done();
})
})
})
describe('with status=205', function(){
it('should respond without a body', function(done){
var app = koa();
app.use(function *(){
this.status = 205;
})
var server = app.listen();
request(server)
.get('/')
.expect(205)
.expect('')
.end(function (err, res) {
if (err) return done(err);
res.header.should.not.have.property('content-type');
done();
})
})
})
describe('with status=304', function(){
it('should respond without a body', function(done){
var app = koa();
app.use(function *(){
this.status = 304;
})
var server = app.listen();
request(server)
.get('/')
.expect(304)
.expect('')
.end(function (err, res) {
if (err) return done(err);
res.header.should.not.have.property('content-type');
done();
})
})
})
})
describe('when .body is a string', function(){
it('should respond', function(done){
var app = koa();