Skip to content

Commit ff5f257

Browse files
committedSep 14, 2017
Fix regression matching multiple ETags in If-None-Match
1 parent e8a4aaf commit ff5f257

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed
 

‎HISTORY.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Fix regression matching multiple ETags in `If-None-Match`
5+
16
0.5.1 / 2017-09-11
27
==================
38

‎index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ function fresh (reqHeaders, resHeaders) {
6363
return false
6464
}
6565

66+
var etagStale = true
6667
var matches = noneMatch.split(TOKEN_LIST_REGEXP)
6768
for (var i = 0; i < matches.length; i++) {
6869
var match = matches[i]
69-
if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) {
70-
return false
70+
if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
71+
etagStale = false
72+
break
7173
}
7274
}
75+
76+
if (etagStale) {
77+
return false
78+
}
7379
}
7480

7581
// if-modified-since

‎test/fresh.js

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ describe('fresh(reqHeaders, resHeaders)', function () {
2828
})
2929
})
3030

31+
describe('when at least one matches', function () {
32+
it('should be fresh', function () {
33+
var reqHeaders = { 'if-none-match': ' "bar" , "foo"' }
34+
var resHeaders = { 'etag': '"foo"' }
35+
assert.ok(fresh(reqHeaders, resHeaders))
36+
})
37+
})
38+
3139
describe('when etag is missing', function () {
3240
it('should be stale', function () {
3341
var reqHeaders = { 'if-none-match': '"foo"' }

0 commit comments

Comments
 (0)
Please sign in to comment.