Fix exception in req.fresh/req.stale without response headers

fixes #2468
This commit is contained in:
Troy Goode 2014-12-11 20:34:26 -08:00 committed by Douglas Christopher Wilson
parent 262b60537f
commit 5d74a553d6
4 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,8 @@
3.x
===
* Fix exception in `req.fresh`/`req.stale` without response headers
3.18.5 / 2014-12-11
===================

View File

@ -526,7 +526,7 @@ req.__defineGetter__('fresh', function(){
// 2xx or 304 as per rfc2616 14.26
if ((s >= 200 && s < 300) || 304 == s) {
return fresh(this.headers, this.res._headers);
return fresh(this.headers, (this.res._headers || {}));
}
return false;

View File

@ -32,5 +32,18 @@ describe('req', function(){
.set('If-None-Match', '"12345"')
.expect(200, 'false', done);
})
it('should return false without response headers', function(done){
var app = express();
app.use(function(req, res){
res._headers = undefined;
res.send(req.fresh);
});
request(app)
.get('/')
.expect(200, 'false', done);
})
})
})

View File

@ -32,5 +32,18 @@ describe('req', function(){
.set('If-None-Match', '"12345"')
.expect(200, 'true', done);
})
it('should return true without response headers', function(done){
var app = express();
app.use(function(req, res){
res._headers = undefined;
res.send(req.stale);
});
request(app)
.get('/')
.expect(200, 'true', done);
})
})
})