@johntalton/http-util 5.1.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johntalton/http-util",
3
- "version": "5.1.1",
3
+ "version": "5.1.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
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 {number} quotaUnits
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 = {
@@ -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 ]>} customHeaders
40
+ * @property {Array<[ CustomHeaderKey, string ]>|undefined} [customHeaders]
41
41
  */
42
42
 
43
43
  /**
@@ -11,7 +11,6 @@ const { HTTP_STATUS_FORBIDDEN} = http2.constants
11
11
  * @param {Metadata} meta
12
12
  */
13
13
  export function sendForbidden(stream, meta) {
14
- throw new Error('unsupported')
15
14
  send(stream, HTTP_STATUS_FORBIDDEN, {
16
15
  }, [], undefined, undefined, meta)
17
16
  }