Backend half
This commit is contained in:
-10
@@ -1,13 +1,3 @@
|
||||
2.0.0 - 2024-09-04
|
||||
==========
|
||||
* Drop support for Node.js <18
|
||||
|
||||
1.0.0 - 2024-09-04
|
||||
==========
|
||||
|
||||
* Drop support for Node.js below 0.8
|
||||
* 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)
|
||||
|
||||
0.5.2 / 2017-09-13
|
||||
==================
|
||||
|
||||
|
||||
+10
-8
@@ -3,7 +3,7 @@
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Node.js Version][node-version-image]][node-version-url]
|
||||
[![Build Status][ci-image]][ci-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
||||
|
||||
HTTP response freshness testing
|
||||
@@ -20,6 +20,8 @@ $ npm install fresh
|
||||
|
||||
## API
|
||||
|
||||
<!-- eslint-disable no-unused-vars -->
|
||||
|
||||
```js
|
||||
var fresh = require('fresh')
|
||||
```
|
||||
@@ -40,7 +42,7 @@ to make handling these requests transparent.
|
||||
|
||||
This module is designed to only follow the HTTP specifications, not
|
||||
to work-around all kinda of client bugs (especially since this module
|
||||
typically does not receive enough information to understand what the
|
||||
typically does not recieve enough information to understand what the
|
||||
client actually is).
|
||||
|
||||
There is a known issue that in certain versions of Safari, Safari
|
||||
@@ -55,16 +57,16 @@ links to further reading on this Safari bug.
|
||||
|
||||
### API usage
|
||||
|
||||
<!-- eslint-disable no-redeclare -->
|
||||
<!-- eslint-disable no-redeclare, no-undef -->
|
||||
|
||||
```js
|
||||
var reqHeaders = { 'if-none-match': '"foo"' }
|
||||
var resHeaders = { etag: '"bar"' }
|
||||
var resHeaders = { 'etag': '"bar"' }
|
||||
fresh(reqHeaders, resHeaders)
|
||||
// => false
|
||||
|
||||
var reqHeaders = { 'if-none-match': '"foo"' }
|
||||
var resHeaders = { etag: '"foo"' }
|
||||
var resHeaders = { 'etag': '"foo"' }
|
||||
fresh(reqHeaders, resHeaders)
|
||||
// => true
|
||||
```
|
||||
@@ -93,7 +95,7 @@ var server = http.createServer(function (req, res) {
|
||||
|
||||
function isFresh (req, res) {
|
||||
return fresh(req.headers, {
|
||||
etag: res.getHeader('ETag'),
|
||||
'etag': res.getHeader('ETag'),
|
||||
'last-modified': res.getHeader('Last-Modified')
|
||||
})
|
||||
}
|
||||
@@ -105,12 +107,12 @@ server.listen(3000)
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[ci-image]: https://img.shields.io/github/workflow/status/jshttp/fresh/ci/master?label=ci
|
||||
[ci-url]: https://github.com/jshttp/fresh/actions/workflows/ci.yml
|
||||
[npm-image]: https://img.shields.io/npm/v/fresh.svg
|
||||
[npm-url]: https://npmjs.org/package/fresh
|
||||
[node-version-image]: https://img.shields.io/node/v/fresh.svg
|
||||
[node-version-url]: https://nodejs.org/en/
|
||||
[travis-image]: https://img.shields.io/travis/jshttp/fresh/master.svg
|
||||
[travis-url]: https://travis-ci.org/jshttp/fresh
|
||||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/fresh/master.svg
|
||||
[coveralls-url]: https://coveralls.io/r/jshttp/fresh?branch=master
|
||||
[downloads-image]: https://img.shields.io/npm/dm/fresh.svg
|
||||
|
||||
+9
-8
@@ -48,26 +48,27 @@ function fresh (reqHeaders, resHeaders) {
|
||||
return false
|
||||
}
|
||||
|
||||
// if-none-match takes precedent over if-modified-since
|
||||
if (noneMatch) {
|
||||
if (noneMatch === '*') {
|
||||
return true
|
||||
}
|
||||
var etag = resHeaders.etag
|
||||
// if-none-match
|
||||
if (noneMatch && noneMatch !== '*') {
|
||||
var etag = resHeaders['etag']
|
||||
|
||||
if (!etag) {
|
||||
return false
|
||||
}
|
||||
|
||||
var etagStale = true
|
||||
var matches = parseTokenList(noneMatch)
|
||||
for (var i = 0; i < matches.length; i++) {
|
||||
var match = matches[i]
|
||||
if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
|
||||
return true
|
||||
etagStale = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
if (etagStale) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// if-modified-since
|
||||
|
||||
+15
-15
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "fresh",
|
||||
"description": "HTTP response freshness testing",
|
||||
"version": "2.0.0",
|
||||
"version": "0.5.2",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
|
||||
"contributors": [
|
||||
"Douglas Christopher Wilson <doug@somethingdoug.com>",
|
||||
@@ -18,15 +18,15 @@
|
||||
"devDependencies": {
|
||||
"beautify-benchmark": "0.2.4",
|
||||
"benchmark": "2.1.4",
|
||||
"eslint": "8.12.0",
|
||||
"eslint-config-standard": "14.1.1",
|
||||
"eslint-plugin-import": "2.25.4",
|
||||
"eslint-plugin-markdown": "2.2.1",
|
||||
"eslint-plugin-node": "11.1.0",
|
||||
"eslint-plugin-promise": "6.0.0",
|
||||
"eslint-plugin-standard": "4.1.0",
|
||||
"mocha": "9.2.0",
|
||||
"nyc": "15.1.0"
|
||||
"eslint": "3.19.0",
|
||||
"eslint-config-standard": "10.2.1",
|
||||
"eslint-plugin-import": "2.7.0",
|
||||
"eslint-plugin-markdown": "1.0.0-beta.6",
|
||||
"eslint-plugin-node": "5.1.1",
|
||||
"eslint-plugin-promise": "3.5.0",
|
||||
"eslint-plugin-standard": "3.0.1",
|
||||
"istanbul": "0.4.5",
|
||||
"mocha": "1.21.5"
|
||||
},
|
||||
"files": [
|
||||
"HISTORY.md",
|
||||
@@ -34,13 +34,13 @@
|
||||
"index.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
"node": ">= 0.6"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "node benchmark/index.js",
|
||||
"lint": "eslint .",
|
||||
"test": "mocha --reporter spec --check-leaks --bail test/",
|
||||
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
|
||||
"test-cov": "nyc --reporter=html --reporter=text npm test"
|
||||
"lint": "eslint --plugin markdown --ext js,md .",
|
||||
"test": "mocha --reporter spec --bail --check-leaks test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user