@serwist/cacheable-response 9.0.0-preview.10 → 9.0.0-preview.11
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.
|
@@ -7,9 +7,7 @@ export interface CacheableResponseOptions {
|
|
|
7
7
|
* A mapping of header names and expected values that a `Response` can have and be
|
|
8
8
|
* considered cacheable. If multiple headers are provided, only one needs to be present.
|
|
9
9
|
*/
|
|
10
|
-
headers?:
|
|
11
|
-
[headerName: string]: string;
|
|
12
|
-
};
|
|
10
|
+
headers?: HeadersInit;
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
13
|
* This class allows you to set up rules determining what
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheableResponse.d.ts","sourceRoot":"","sources":["../src/CacheableResponse.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE
|
|
1
|
+
{"version":3,"file":"CacheableResponse.d.ts","sourceRoot":"","sources":["../src/CacheableResponse.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAuC;IAClE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAU;IAEpC;;;;;;;;OAQG;gBACS,MAAM,GAAE,wBAA6B;IAmCjD;;;;;;;;OAQG;IACH,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;CAyDjD"}
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,9 @@ class CacheableResponse {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
this._statuses = config.statuses;
|
|
33
|
-
|
|
33
|
+
if (config.headers) {
|
|
34
|
+
this._headers = new Headers(config.headers);
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
isResponseCacheable(response) {
|
|
36
38
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -46,9 +48,12 @@ class CacheableResponse {
|
|
|
46
48
|
cacheable = this._statuses.includes(response.status);
|
|
47
49
|
}
|
|
48
50
|
if (this._headers && cacheable) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
for (const [headerName, headerValue] of this._headers.entries()){
|
|
52
|
+
if (response.headers.get(headerName) !== headerValue) {
|
|
53
|
+
cacheable = false;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
if (process.env.NODE_ENV !== "production") {
|
|
54
59
|
if (!cacheable) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/cacheable-response",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.11",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "A module that takes a Response object and determines whether it's cacheable based on a specific configuration.",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
8
|
"dist"
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@serwist/core": "9.0.0-preview.
|
|
32
|
+
"@serwist/core": "9.0.0-preview.11"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"rollup": "4.9.6",
|
|
36
36
|
"typescript": "5.4.0-dev.20240206",
|
|
37
|
-
"@serwist/constants": "9.0.0-preview.
|
|
37
|
+
"@serwist/constants": "9.0.0-preview.11"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"typescript": ">=5.0.0"
|
package/src/CacheableResponse.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface CacheableResponseOptions {
|
|
|
17
17
|
* A mapping of header names and expected values that a `Response` can have and be
|
|
18
18
|
* considered cacheable. If multiple headers are provided, only one needs to be present.
|
|
19
19
|
*/
|
|
20
|
-
headers?:
|
|
20
|
+
headers?: HeadersInit;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -28,7 +28,7 @@ export interface CacheableResponseOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
export class CacheableResponse {
|
|
30
30
|
private readonly _statuses?: CacheableResponseOptions["statuses"];
|
|
31
|
-
private readonly _headers?:
|
|
31
|
+
private readonly _headers?: Headers;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* To construct a new CacheableResponse instance you must provide at least
|
|
@@ -69,7 +69,9 @@ export class CacheableResponse {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
this._statuses = config.statuses;
|
|
72
|
-
|
|
72
|
+
if (config.headers) {
|
|
73
|
+
this._headers = new Headers(config.headers);
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
@@ -98,9 +100,12 @@ export class CacheableResponse {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
if (this._headers && cacheable) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
for (const [headerName, headerValue] of this._headers.entries()) {
|
|
104
|
+
if (response.headers.get(headerName) !== headerValue) {
|
|
105
|
+
cacheable = false;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
if (process.env.NODE_ENV !== "production") {
|