Skip to content

Commit 7015bce

Browse files
billouboqdougwilson
authored andcommittedSep 12, 2017
perf: improve ETag match loop
closes #22
1 parent 7a2b460 commit 7015bce

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

‎HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unreleased
22
==========
33

44
* Fix handling of modified headers with invalid dates
5+
* perf: improve ETag match loop
56

67
0.5.0 / 2017-02-21
78
==================

‎index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ function fresh (reqHeaders, resHeaders) {
5858
// if-none-match
5959
if (noneMatch && noneMatch !== '*') {
6060
var etag = resHeaders['etag']
61-
var etagStale = !etag || noneMatch.split(TOKEN_LIST_REGEXP).every(function (match) {
62-
return match !== etag && match !== 'W/' + etag && 'W/' + match !== etag
63-
})
6461

65-
if (etagStale) {
62+
if (!etag) {
6663
return false
6764
}
65+
66+
var matches = noneMatch.split(TOKEN_LIST_REGEXP)
67+
for (var i = 0; i < matches.length; i++) {
68+
var match = matches[i]
69+
if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) {
70+
return false
71+
}
72+
}
6873
}
6974

7075
// if-modified-since

0 commit comments

Comments
 (0)
Please sign in to comment.