Skip to content

Commit

Permalink
Remove usage of res._headers private field
Browse files Browse the repository at this point in the history
closes #3174
  • Loading branch information
dougwilson committed Feb 21, 2017
1 parent cd7d241 commit f87abb3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ unreleased
==========

* Add debug message when loading view engine
* Remove usage of `res._headers` private field
- Improves compatibility with Node.js 8 nightly
* deps: debug@2.6.1
- Allow colors in workers
- Deprecated `DEBUG_FD` environment variable set to `3` or higher
Expand Down
10 changes: 7 additions & 3 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,18 @@ defineGetter(req, 'host', deprecate.function(function host(){

defineGetter(req, 'fresh', function(){
var method = this.method;
var s = this.res.statusCode;
var res = this.res
var status = res.statusCode

// GET or HEAD for weak freshness validation only
if ('GET' !== method && 'HEAD' !== method) return false;

// 2xx or 304 as per rfc2616 14.26
if ((s >= 200 && s < 300) || 304 === s) {
return fresh(this.headers, (this.res._headers || {}));
if ((status >= 200 && status < 300) || 304 === status) {
return fresh(this.headers, {
'etag': res.get('ETag'),
'last-modified': res.get('Last-Modified')
})
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion test/req.fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('req', function(){
it('should return false without response headers', function(done){
var app = express();

app.disable('x-powered-by')
app.use(function(req, res){
res._headers = null;
res.send(req.fresh);
});

Expand Down
2 changes: 1 addition & 1 deletion test/req.stale.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('req', function(){
it('should return true without response headers', function(done){
var app = express();

app.disable('x-powered-by')
app.use(function(req, res){
res._headers = null;
res.send(req.stale);
});

Expand Down

0 comments on commit f87abb3

Please sign in to comment.