Skip to content

Commit 6e22588

Browse files
authored
feat: support web standards (#4)
1 parent eefc726 commit 6e22588

25 files changed

+6802
-2659
lines changed

.eslintrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"env": {
3-
"node": true,
3+
"worker": true,
44
"es6": true,
5-
"mocha": true
5+
"jest": true
66
}
7-
}
7+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
.nyc_output/
33
coverage/
44
node4/
5+
dist/

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Can I cache this? [![Build Status](https://travis-ci.org/kornelski/http-cache-semantics.svg?branch=master)](https://travis-ci.org/kornelski/http-cache-semantics)
22

3+
> This library is forked from [http-cache-semantics](https://github.com/kornelski/http-cache-semantics), adding support for web standards and exporting in ESM format.
4+
35
`CachePolicy` tells when responses can be reused from a cache, taking into account [HTTP RFC 7234](http://httpwg.org/specs/rfc7234.html) rules for user agents and shared caches.
46
It also implements [RFC 5861](https://tools.ietf.org/html/rfc5861), implementing `stale-if-error` and `stale-while-revalidate`.
57
It's aware of many tricky details such as the `Vary` header, proxy revalidation, and authenticated responses.
@@ -47,20 +49,19 @@ The key method is `satisfiesWithoutRevalidation(newRequest)`, which checks wheth
4749
Request and response must have a `headers` property with all header names in lower case. `url`, `status` and `method` are optional (defaults are any URL, status `200`, and `GET` method).
4850

4951
```js
50-
const request = {
51-
url: '/',
52+
const request = new Request('http://localhost/', {
5253
method: 'GET',
5354
headers: {
5455
accept: '*/*',
5556
},
56-
};
57+
});
5758

58-
const response = {
59+
const response = new Response(null, {
5960
status: 200,
6061
headers: {
6162
'cache-control': 'public, max-age=7234',
6263
},
63-
};
64+
});
6465

6566
const options = {
6667
shared: true,
@@ -200,4 +201,4 @@ Per the RFC, the cache should take into account the time between server-supplied
200201
* Servers with incorrectly set timezone may add several hours to cache age (or more, if the clock is completely wrong).
201202
* Even reasonably correct clocks may be off by a couple of seconds, breaking `max-age=1` trick (which is useful for reverse proxies on high-traffic servers).
202203

203-
Previous versions of this library had an option to ignore the server date if it was "too inaccurate". To support the `max-age=1` trick the library also has to ignore dates that pretty accurate. There's no point of having an option to trust dates that are only a bit inaccurate, so this library won't trust any server dates. `max-age` will be interpreted from the time the response has been received, not from when it has been sent. This will affect only [RFC 1149 networks](https://tools.ietf.org/html/rfc1149).
204+
Previous versions of this library had an option to ignore the server date if it was "too inaccurate". To support the `max-age=1` trick the library also has to ignore dates that pretty accurate. There's no point of having an option to trust dates that are only a bit inaccurate, so this library won't trust any server dates. `max-age` will be interpreted from the time the response has been received, not from when it has been sent. This will affect only [RFC 1149 networks](https://tools.ietf.org/html/rfc1149).

0 commit comments

Comments
 (0)