Skip to content

Commit

Permalink
perf: improve ETag match loop
Browse files Browse the repository at this point in the history
closes #22
  • Loading branch information
billouboq authored and dougwilson committed Sep 12, 2017
1 parent 7a2b460 commit 7015bce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 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
==========

* Fix handling of modified headers with invalid dates
* perf: improve ETag match loop

0.5.0 / 2017-02-21
==================
Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7015bce

Please sign in to comment.