Skip to content

Commit cff1222

Browse files
authored
Merge pull request #38 from bigbigDreamer/fix/ISSUE-35
Fix: Expect return true immediately if If-None-Match matches the ETag header (#35)
2 parents 86b4548 + 846caac commit cff1222

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unreleased
22
==========
33

44
* Drop support for Node.js below 0.8
5+
* 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)
56

67
0.5.2 / 2017-09-13
78
==================

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,26 @@ function fresh (reqHeaders, resHeaders) {
4848
return false
4949
}
5050

51-
// if-none-match
52-
if (noneMatch && noneMatch !== '*') {
51+
// if-none-match takes precedent over if-modified-since
52+
if (noneMatch) {
53+
if (noneMatch === '*') {
54+
return true
55+
}
5356
var etag = resHeaders.etag
5457

5558
if (!etag) {
5659
return false
5760
}
5861

59-
var etagStale = true
6062
var matches = parseTokenList(noneMatch)
6163
for (var i = 0; i < matches.length; i++) {
6264
var match = matches[i]
6365
if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
64-
etagStale = false
65-
break
66+
return true
6667
}
6768
}
6869

69-
if (etagStale) {
70-
return false
71-
}
70+
return false
7271
}
7372

7473
// if-modified-since

test/fresh.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ describe('fresh(reqHeaders, resHeaders)', function () {
139139
})
140140

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

0 commit comments

Comments
 (0)