diff --git a/HISTORY.md b/HISTORY.md index e463052..f2dd739 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ unreleased ========== * Fix handling of modified headers with invalid dates + * perf: improve ETag match loop 0.5.0 / 2017-02-21 ================== diff --git a/index.js b/index.js index dd49dee..86b61c8 100644 --- a/index.js +++ b/index.js @@ -58,13 +58,18 @@ function fresh (reqHeaders, resHeaders) { // if-none-match if (noneMatch && noneMatch !== '*') { var etag = resHeaders['etag'] - var etagStale = !etag || noneMatch.split(TOKEN_LIST_REGEXP).every(function (match) { - return match !== etag && match !== 'W/' + etag && 'W/' + match !== etag - }) - if (etagStale) { + if (!etag) { return false } + + var matches = noneMatch.split(TOKEN_LIST_REGEXP) + for (var i = 0; i < matches.length; i++) { + var match = matches[i] + if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) { + return false + } + } } // if-modified-since