fresh 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/HISTORY.md +6 -0
  2. package/index.js +45 -10
  3. package/package.json +1 -1
package/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.2 / 2017-09-13
2
+ ==================
3
+
4
+ * Fix regression matching multiple ETags in `If-None-Match`
5
+ * perf: improve `If-None-Match` token parsing
6
+
1
7
  0.5.1 / 2017-09-11
2
8
  ==================
3
9
 
package/index.js CHANGED
@@ -14,13 +14,6 @@
14
14
 
15
15
  var CACHE_CONTROL_NO_CACHE_REGEXP = /(?:^|,)\s*?no-cache\s*?(?:,|$)/
16
16
 
17
- /**
18
- * Simple expression to split token list.
19
- * @private
20
- */
21
-
22
- var TOKEN_LIST_REGEXP = / *, */
23
-
24
17
  /**
25
18
  * Module exports.
26
19
  * @public
@@ -63,13 +56,19 @@ function fresh (reqHeaders, resHeaders) {
63
56
  return false
64
57
  }
65
58
 
66
- var matches = noneMatch.split(TOKEN_LIST_REGEXP)
59
+ var etagStale = true
60
+ var matches = parseTokenList(noneMatch)
67
61
  for (var i = 0; i < matches.length; i++) {
68
62
  var match = matches[i]
69
- if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) {
70
- return false
63
+ if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
64
+ etagStale = false
65
+ break
71
66
  }
72
67
  }
68
+
69
+ if (etagStale) {
70
+ return false
71
+ }
73
72
  }
74
73
 
75
74
  // if-modified-since
@@ -100,3 +99,39 @@ function parseHttpDate (date) {
100
99
  ? timestamp
101
100
  : NaN
102
101
  }
102
+
103
+ /**
104
+ * Parse a HTTP token list.
105
+ *
106
+ * @param {string} str
107
+ * @private
108
+ */
109
+
110
+ function parseTokenList (str) {
111
+ var end = 0
112
+ var list = []
113
+ var start = 0
114
+
115
+ // gather tokens
116
+ for (var i = 0, len = str.length; i < len; i++) {
117
+ switch (str.charCodeAt(i)) {
118
+ case 0x20: /* */
119
+ if (start === end) {
120
+ start = end = i + 1
121
+ }
122
+ break
123
+ case 0x2c: /* , */
124
+ list.push(str.substring(start, end))
125
+ start = end = i + 1
126
+ break
127
+ default:
128
+ end = i + 1
129
+ break
130
+ }
131
+ }
132
+
133
+ // final token
134
+ list.push(str.substring(start, end))
135
+
136
+ return list
137
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fresh",
3
3
  "description": "HTTP response freshness testing",
4
- "version": "0.5.1",
4
+ "version": "0.5.2",
5
5
  "author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
6
6
  "contributors": [
7
7
  "Douglas Christopher Wilson <doug@somethingdoug.com>",