Skip to content

Commit

Permalink
Merge pull request #38 from bigbigDreamer/fix/ISSUE-35
Browse files Browse the repository at this point in the history
Fix: Expect return true immediately if If-None-Match matches the ETag header (#35)
  • Loading branch information
jonchurch authored Sep 4, 2024
2 parents 86b4548 + 846caac commit cff1222
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ unreleased
==========

* Drop support for Node.js below 0.8
* Fix: Ignore `If-Modified-Since` in the presence of `If-None-Match`, according to [spec](https://www.rfc-editor.org/rfc/rfc9110.html#section-13.1.3-5). Fixes [#35](https://github.com/jshttp/fresh/issues/35)

0.5.2 / 2017-09-13
==================
Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,26 @@ function fresh (reqHeaders, resHeaders) {
return false
}

// if-none-match
if (noneMatch && noneMatch !== '*') {
// if-none-match takes precedent over if-modified-since
if (noneMatch) {
if (noneMatch === '*') {
return true
}
var etag = resHeaders.etag

if (!etag) {
return false
}

var etagStale = true
var matches = parseTokenList(noneMatch)
for (var i = 0; i < matches.length; i++) {
var match = matches[i]
if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
etagStale = false
break
return true
}
}

if (etagStale) {
return false
}
return false
}

// if-modified-since
Expand Down
4 changes: 2 additions & 2 deletions test/fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ describe('fresh(reqHeaders, resHeaders)', function () {
})

describe('when only ETag matches', function () {
it('should be stale', function () {
it('should be fresh', function () {
var reqHeaders = { 'if-none-match': '"foo"', 'if-modified-since': 'Sat, 01 Jan 2000 00:00:00 GMT' }
var resHeaders = { etag: '"foo"', 'last-modified': 'Sat, 01 Jan 2000 01:00:00 GMT' }
assert.ok(!fresh(reqHeaders, resHeaders))
assert.ok(fresh(reqHeaders, resHeaders))
})
})

Expand Down

0 comments on commit cff1222

Please sign in to comment.