@johntalton/http-util 5.1.2 → 5.1.4
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.
- package/package.json +1 -1
- package/src/link.js +35 -0
- package/src/rate-limit.js +2 -2
- package/src/response/defs.js +1 -1
package/package.json
CHANGED
package/src/link.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} LinkItem
|
|
3
|
+
* @property {string} url
|
|
4
|
+
* @property {string|undefined} [relation]
|
|
5
|
+
* @property {Map<string, string>|undefined} [parameters]
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class Link {
|
|
9
|
+
/**
|
|
10
|
+
* @param {LinkItem} link
|
|
11
|
+
*/
|
|
12
|
+
static *#encode(link) {
|
|
13
|
+
const encodedUri = encodeURI(link.url)
|
|
14
|
+
|
|
15
|
+
yield `<${encodedUri}>`
|
|
16
|
+
if(link.relation !== undefined) { yield `rel="${link.relation}"` }
|
|
17
|
+
if(link.parameters === undefined) { return }
|
|
18
|
+
for(const [ key, value ] of link.parameters) {
|
|
19
|
+
yield `${key}="${value}"`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {LinkItem} link
|
|
26
|
+
*/
|
|
27
|
+
static encode(link) {
|
|
28
|
+
return [ ...Link.#encode(link) ].join('; ')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// console.log(Link.encode({ url: '/index.html', parameters: new Map([ [ 'as', 'style' ], [ 'fetchpriority', 'high' ] ]) }))
|
|
33
|
+
// console.log(Link.encode({ url: '/index.html', relation: 'next', parameters: new Map([ [ 'fetchpriority', 'high' ] ]) }))
|
|
34
|
+
// console.log(Link.encode({ url: '/index.html', relation: 'next' }))
|
|
35
|
+
// console.log(Link.encode({ url: 'https://example.com/苗条', relation: 'preconnect' }))
|
package/src/rate-limit.js
CHANGED
|
@@ -16,9 +16,9 @@ export const HTTP_HEADER_RATE_LIMIT_POLICY = 'RateLimit-Policy'
|
|
|
16
16
|
* @property {string} name
|
|
17
17
|
* @property {number} quota
|
|
18
18
|
* @property {number} size
|
|
19
|
-
* @property {
|
|
19
|
+
* @property {string} quotaUnits
|
|
20
20
|
* @property {number} windowSeconds
|
|
21
|
-
* @property {string} [partitionKey]
|
|
21
|
+
* @property {string|undefined} [partitionKey]
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
export const LIMIT_PARAMETERS = {
|
package/src/response/defs.js
CHANGED
|
@@ -37,7 +37,7 @@ export const RANGE_UNITS_NONE = 'none'
|
|
|
37
37
|
* @property {Array<TimingsInfo>} performance
|
|
38
38
|
* @property {string|undefined} servername
|
|
39
39
|
* @property {string|undefined} origin
|
|
40
|
-
* @property {Array<[ CustomHeaderKey, string ]
|
|
40
|
+
* @property {Array<[ CustomHeaderKey, string ]>|undefined} [customHeaders]
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
/**
|