fresh 0.5.1 → 1.0.0

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 (4) hide show
  1. package/HISTORY.md +12 -0
  2. package/README.md +8 -10
  3. package/index.js +47 -13
  4. package/package.json +15 -15
package/HISTORY.md CHANGED
@@ -1,3 +1,15 @@
1
+ 1.0.0 - 2024-09-04
2
+ ==========
3
+
4
+ * Drop support for Node.js below 0.8
5
+ * Fix: Ignore `If-Modified-Since` in the presence of `If-None-Match`, according to [spec](https://www.rfc-editor.org/rfc/rfc9110.html#section-13.1.3-5). Fixes [#35](https://github.com/jshttp/fresh/issues/35)
6
+
7
+ 0.5.2 / 2017-09-13
8
+ ==================
9
+
10
+ * Fix regression matching multiple ETags in `If-None-Match`
11
+ * perf: improve `If-None-Match` token parsing
12
+
1
13
  0.5.1 / 2017-09-11
2
14
  ==================
3
15
 
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![NPM Version][npm-image]][npm-url]
4
4
  [![NPM Downloads][downloads-image]][downloads-url]
5
5
  [![Node.js Version][node-version-image]][node-version-url]
6
- [![Build Status][travis-image]][travis-url]
6
+ [![Build Status][ci-image]][ci-url]
7
7
  [![Test Coverage][coveralls-image]][coveralls-url]
8
8
 
9
9
  HTTP response freshness testing
@@ -20,8 +20,6 @@ $ npm install fresh
20
20
 
21
21
  ## API
22
22
 
23
- <!-- eslint-disable no-unused-vars -->
24
-
25
23
  ```js
26
24
  var fresh = require('fresh')
27
25
  ```
@@ -42,7 +40,7 @@ to make handling these requests transparent.
42
40
 
43
41
  This module is designed to only follow the HTTP specifications, not
44
42
  to work-around all kinda of client bugs (especially since this module
45
- typically does not recieve enough information to understand what the
43
+ typically does not receive enough information to understand what the
46
44
  client actually is).
47
45
 
48
46
  There is a known issue that in certain versions of Safari, Safari
@@ -57,16 +55,16 @@ links to further reading on this Safari bug.
57
55
 
58
56
  ### API usage
59
57
 
60
- <!-- eslint-disable no-redeclare, no-undef -->
58
+ <!-- eslint-disable no-redeclare -->
61
59
 
62
60
  ```js
63
61
  var reqHeaders = { 'if-none-match': '"foo"' }
64
- var resHeaders = { 'etag': '"bar"' }
62
+ var resHeaders = { etag: '"bar"' }
65
63
  fresh(reqHeaders, resHeaders)
66
64
  // => false
67
65
 
68
66
  var reqHeaders = { 'if-none-match': '"foo"' }
69
- var resHeaders = { 'etag': '"foo"' }
67
+ var resHeaders = { etag: '"foo"' }
70
68
  fresh(reqHeaders, resHeaders)
71
69
  // => true
72
70
  ```
@@ -95,7 +93,7 @@ var server = http.createServer(function (req, res) {
95
93
 
96
94
  function isFresh (req, res) {
97
95
  return fresh(req.headers, {
98
- 'etag': res.getHeader('ETag'),
96
+ etag: res.getHeader('ETag'),
99
97
  'last-modified': res.getHeader('Last-Modified')
100
98
  })
101
99
  }
@@ -107,12 +105,12 @@ server.listen(3000)
107
105
 
108
106
  [MIT](LICENSE)
109
107
 
108
+ [ci-image]: https://img.shields.io/github/workflow/status/jshttp/fresh/ci/master?label=ci
109
+ [ci-url]: https://github.com/jshttp/fresh/actions/workflows/ci.yml
110
110
  [npm-image]: https://img.shields.io/npm/v/fresh.svg
111
111
  [npm-url]: https://npmjs.org/package/fresh
112
112
  [node-version-image]: https://img.shields.io/node/v/fresh.svg
113
113
  [node-version-url]: https://nodejs.org/en/
114
- [travis-image]: https://img.shields.io/travis/jshttp/fresh/master.svg
115
- [travis-url]: https://travis-ci.org/jshttp/fresh
116
114
  [coveralls-image]: https://img.shields.io/coveralls/jshttp/fresh/master.svg
117
115
  [coveralls-url]: https://coveralls.io/r/jshttp/fresh?branch=master
118
116
  [downloads-image]: https://img.shields.io/npm/dm/fresh.svg
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
@@ -55,21 +48,26 @@ function fresh (reqHeaders, resHeaders) {
55
48
  return false
56
49
  }
57
50
 
58
- // if-none-match
59
- if (noneMatch && noneMatch !== '*') {
60
- var etag = resHeaders['etag']
51
+ // if-none-match takes precedent over if-modified-since
52
+ if (noneMatch) {
53
+ if (noneMatch === '*') {
54
+ return true
55
+ }
56
+ var etag = resHeaders.etag
61
57
 
62
58
  if (!etag) {
63
59
  return false
64
60
  }
65
61
 
66
- var matches = noneMatch.split(TOKEN_LIST_REGEXP)
62
+ var matches = parseTokenList(noneMatch)
67
63
  for (var i = 0; i < matches.length; i++) {
68
64
  var match = matches[i]
69
- if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) {
70
- return false
65
+ if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
66
+ return true
71
67
  }
72
68
  }
69
+
70
+ return false
73
71
  }
74
72
 
75
73
  // if-modified-since
@@ -100,3 +98,39 @@ function parseHttpDate (date) {
100
98
  ? timestamp
101
99
  : NaN
102
100
  }
101
+
102
+ /**
103
+ * Parse a HTTP token list.
104
+ *
105
+ * @param {string} str
106
+ * @private
107
+ */
108
+
109
+ function parseTokenList (str) {
110
+ var end = 0
111
+ var list = []
112
+ var start = 0
113
+
114
+ // gather tokens
115
+ for (var i = 0, len = str.length; i < len; i++) {
116
+ switch (str.charCodeAt(i)) {
117
+ case 0x20: /* */
118
+ if (start === end) {
119
+ start = end = i + 1
120
+ }
121
+ break
122
+ case 0x2c: /* , */
123
+ list.push(str.substring(start, end))
124
+ start = end = i + 1
125
+ break
126
+ default:
127
+ end = i + 1
128
+ break
129
+ }
130
+ }
131
+
132
+ // final token
133
+ list.push(str.substring(start, end))
134
+
135
+ return list
136
+ }
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": "1.0.0",
5
5
  "author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
6
6
  "contributors": [
7
7
  "Douglas Christopher Wilson <doug@somethingdoug.com>",
@@ -18,15 +18,15 @@
18
18
  "devDependencies": {
19
19
  "beautify-benchmark": "0.2.4",
20
20
  "benchmark": "2.1.4",
21
- "eslint": "3.19.0",
22
- "eslint-config-standard": "10.2.1",
23
- "eslint-plugin-import": "2.7.0",
24
- "eslint-plugin-markdown": "1.0.0-beta.6",
25
- "eslint-plugin-node": "5.1.1",
26
- "eslint-plugin-promise": "3.5.0",
27
- "eslint-plugin-standard": "3.0.1",
28
- "istanbul": "0.4.5",
29
- "mocha": "1.21.5"
21
+ "eslint": "8.12.0",
22
+ "eslint-config-standard": "14.1.1",
23
+ "eslint-plugin-import": "2.25.4",
24
+ "eslint-plugin-markdown": "2.2.1",
25
+ "eslint-plugin-node": "11.1.0",
26
+ "eslint-plugin-promise": "6.0.0",
27
+ "eslint-plugin-standard": "4.1.0",
28
+ "mocha": "9.2.0",
29
+ "nyc": "15.1.0"
30
30
  },
31
31
  "files": [
32
32
  "HISTORY.md",
@@ -34,13 +34,13 @@
34
34
  "index.js"
35
35
  ],
36
36
  "engines": {
37
- "node": ">= 0.6"
37
+ "node": ">= 0.8"
38
38
  },
39
39
  "scripts": {
40
40
  "bench": "node benchmark/index.js",
41
- "lint": "eslint --plugin markdown --ext js,md .",
42
- "test": "mocha --reporter spec --bail --check-leaks test/",
43
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
44
- "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
41
+ "lint": "eslint .",
42
+ "test": "mocha --reporter spec --check-leaks --bail test/",
43
+ "test-ci": "nyc --reporter=lcov --reporter=text npm test",
44
+ "test-cov": "nyc --reporter=html --reporter=text npm test"
45
45
  }
46
46
  }