@johntalton/http-util 6.1.0 → 7.0.2

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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -1
  3. package/src/body.js +11 -6
  4. package/src/defs.js +14 -5
  5. package/src/headers/accept-encoding.js +28 -5
  6. package/src/headers/accept-language.js +29 -5
  7. package/src/headers/accept.js +77 -32
  8. package/src/headers/cache-control.js +6 -3
  9. package/src/headers/client-hints.js +4 -3
  10. package/src/headers/conditional.js +18 -18
  11. package/src/headers/content-type.js +1 -1
  12. package/src/headers/link.js +9 -4
  13. package/src/headers/multipart.js +18 -17
  14. package/src/headers/range.js +4 -2
  15. package/src/headers/rate-limit.js +20 -4
  16. package/src/headers/server-timing.js +5 -3
  17. package/src/headers/util/kvp.js +2 -1
  18. package/src/headers/util/mime.js +17 -1
  19. package/src/headers/util/quote.js +1 -1
  20. package/src/headers/util/whitespace.js +1 -1
  21. package/src/headers/www-authenticate.js +35 -11
  22. package/src/response/2xx/accepted.js +2 -2
  23. package/src/response/2xx/bytes.js +2 -31
  24. package/src/response/2xx/created.js +8 -21
  25. package/src/response/2xx/json.js +6 -19
  26. package/src/response/2xx/no-content.js +4 -18
  27. package/src/response/2xx/partial-content.js +1 -28
  28. package/src/response/2xx/preflight.js +18 -25
  29. package/src/response/3xx/found.js +8 -6
  30. package/src/response/3xx/moved-permanently.js +8 -6
  31. package/src/response/3xx/multiple-choices.js +3 -3
  32. package/src/response/3xx/not-modified.js +14 -26
  33. package/src/response/3xx/permanent-redirect.js +7 -5
  34. package/src/response/3xx/see-other.js +8 -6
  35. package/src/response/3xx/temporary-redirect.js +7 -5
  36. package/src/response/4xx/bad-request.js +2 -3
  37. package/src/response/4xx/conflict.js +2 -2
  38. package/src/response/4xx/content-too-large.js +2 -2
  39. package/src/response/4xx/forbidden.js +3 -3
  40. package/src/response/4xx/gone.js +2 -2
  41. package/src/response/4xx/im-a-teapot.js +2 -2
  42. package/src/response/4xx/not-acceptable.js +2 -11
  43. package/src/response/4xx/not-allowed.js +6 -14
  44. package/src/response/4xx/payment-required.js +4 -4
  45. package/src/response/4xx/precondition-failed.js +4 -18
  46. package/src/response/4xx/range-not-satisfiable.js +4 -13
  47. package/src/response/4xx/timeout.js +3 -3
  48. package/src/response/4xx/too-many-requests.js +3 -20
  49. package/src/response/4xx/unauthorized.js +4 -4
  50. package/src/response/4xx/unprocessable.js +2 -2
  51. package/src/response/4xx/unsupported-media.js +16 -23
  52. package/src/response/5xx/error.js +2 -3
  53. package/src/response/5xx/insufficient-storage.js +2 -2
  54. package/src/response/5xx/not-implemented.js +2 -3
  55. package/src/response/5xx/unavailable.js +3 -20
  56. package/src/response/header-util.js +9 -5
  57. package/src/response/response.js +2 -2
  58. package/src/response/send-util.js +102 -30
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,9 +12,9 @@ const { HTTP_STATUS_MULTIPLE_CHOICES } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendMultipleChoices(stream, meta) {
15
- send(stream, HTTP_STATUS_MULTIPLE_CHOICES, {
15
+ send_no_body(stream, HTTP_STATUS_MULTIPLE_CHOICES, {
16
16
  // Alternates:
17
17
  // TCN: list
18
18
  // Vary: negotiate
19
- }, [], undefined, undefined, meta)
19
+ }, [], meta)
20
20
  }
@@ -1,47 +1,32 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
+ import { COMMON_LIST_VALUE_JOINER_COMMA } from '../../defs.js'
4
+
3
5
  import { CacheControl } from '../../headers/cache-control.js'
4
6
  import { Conditional } from '../../headers/conditional.js'
5
- import { send } from '../send-util.js'
7
+ import { send_no_body } from '../send-util.js'
6
8
 
7
9
  /** @import { ServerHttp2Stream } from 'node:http2' */
8
10
  /** @import { SendContent, Metadata } from '../../defs.js' */
9
- /** @import { EtagItem, IMFFixDateInput } from '../../headers/conditional.js' */
10
- /** @import { CacheControlOptions } from '../../headers/cache-control.js' */
11
11
 
12
12
  const {
13
13
  HTTP2_HEADER_AGE,
14
14
  HTTP2_HEADER_ETAG,
15
15
  HTTP2_HEADER_LAST_MODIFIED,
16
16
  HTTP2_HEADER_VARY,
17
- HTTP2_HEADER_CACHE_CONTROL
17
+ HTTP2_HEADER_CACHE_CONTROL,
18
+ HTTP2_HEADER_ACCEPT,
19
+ HTTP2_HEADER_ACCEPT_ENCODING
18
20
  } = http2.constants
19
21
 
20
22
  const { HTTP_STATUS_NOT_MODIFIED } = http2.constants
21
23
 
22
- /**
23
- * @param {ServerHttp2Stream} stream
24
- * @param {EtagItem|undefined} etag
25
- * @param {IMFFixDateInput|string|undefined} lastModified
26
- * @param {number|undefined} age
27
- * @param {CacheControlOptions} cacheControl
28
- * @param {Metadata} meta
29
- */
30
- export function sendNotModified(stream, etag, lastModified, age, cacheControl, meta) {
31
- _sendNotModified(stream, {
32
- etag,
33
- lastModified,
34
- age,
35
- cacheControl
36
- }, meta)
37
- }
38
-
39
24
  /**
40
25
  * @param {ServerHttp2Stream} stream
41
26
  * @param {Pick<SendContent, 'etag' | 'lastModified' | 'age' | 'cacheControl'>} content
42
27
  * @param {Metadata} meta
43
28
  */
44
- export function _sendNotModified(stream, content, meta) {
29
+ export function sendNotModified(stream, content, meta) {
45
30
  const {
46
31
  etag,
47
32
  lastModified,
@@ -49,11 +34,14 @@ export function _sendNotModified(stream, content, meta) {
49
34
  cacheControl
50
35
  } = content
51
36
 
52
- send(stream, HTTP_STATUS_NOT_MODIFIED, {
53
- [HTTP2_HEADER_VARY]: 'Accept, Accept-Encoding',
37
+ const varyHeaders = [ HTTP2_HEADER_ACCEPT, HTTP2_HEADER_ACCEPT_ENCODING ]
38
+
39
+ send_no_body(stream, HTTP_STATUS_NOT_MODIFIED, {
40
+ // todo Content-Location
41
+ [HTTP2_HEADER_VARY]: varyHeaders.join(COMMON_LIST_VALUE_JOINER_COMMA),
54
42
  [HTTP2_HEADER_CACHE_CONTROL]: CacheControl.encode(cacheControl),
55
43
  [HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
56
44
  [HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified),
57
- [HTTP2_HEADER_AGE]: age === undefined ? undefined : `${age}`
58
- }, [ HTTP2_HEADER_AGE ], undefined, undefined, meta)
45
+ [HTTP2_HEADER_AGE]: Number.isInteger(age) ? `${age}` : undefined
46
+ }, [ HTTP2_HEADER_AGE ], meta)
59
47
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -13,11 +13,13 @@ const { HTTP_STATUS_PERMANENT_REDIRECT } = http2.constants
13
13
 
14
14
  /**
15
15
  * @param {ServerHttp2Stream} stream
16
- * @param {URL} location
16
+ * @param {URL|string} location
17
17
  * @param {Metadata} meta
18
18
  */
19
19
  export function sendPermanentRedirect(stream, location, meta) {
20
- send(stream, HTTP_STATUS_PERMANENT_REDIRECT, {
21
- [HTTP2_HEADER_LOCATION]: location.href
22
- }, [ HTTP2_HEADER_LOCATION ], undefined, undefined, meta)
20
+ const loc = (location instanceof URL) ? location.href : location
21
+
22
+ send_no_body(stream, HTTP_STATUS_PERMANENT_REDIRECT, {
23
+ [HTTP2_HEADER_LOCATION]: loc
24
+ }, [ HTTP2_HEADER_LOCATION ], meta)
23
25
  }
@@ -1,23 +1,25 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
7
7
 
8
8
  const {
9
- HTTP2_HEADER_LOCATION
9
+ HTTP2_HEADER_LOCATION
10
10
  } = http2.constants
11
11
 
12
12
  const { HTTP_STATUS_SEE_OTHER } = http2.constants
13
13
 
14
14
  /**
15
15
  * @param {ServerHttp2Stream} stream
16
- * @param {URL} location
16
+ * @param {URL|string} location
17
17
  * @param {Metadata} meta
18
18
  */
19
19
  export function sendSeeOther(stream, location, meta) {
20
- send(stream, HTTP_STATUS_SEE_OTHER, {
21
- [HTTP2_HEADER_LOCATION]: location.href
22
- }, [ HTTP2_HEADER_LOCATION ], undefined, undefined, meta)
20
+ const loc = (location instanceof URL) ? location.href : location
21
+
22
+ send_no_body(stream, HTTP_STATUS_SEE_OTHER, {
23
+ [HTTP2_HEADER_LOCATION]: loc
24
+ }, [HTTP2_HEADER_LOCATION], meta)
23
25
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -13,11 +13,13 @@ const { HTTP_STATUS_TEMPORARY_REDIRECT } = http2.constants
13
13
 
14
14
  /**
15
15
  * @param {ServerHttp2Stream} stream
16
- * @param {URL} location
16
+ * @param {URL|string} location
17
17
  * @param {Metadata} meta
18
18
  */
19
19
  export function sendTemporaryRedirect(stream, location, meta) {
20
- send(stream, HTTP_STATUS_TEMPORARY_REDIRECT, {
21
- [HTTP2_HEADER_LOCATION]: location.href
22
- }, [ HTTP2_HEADER_LOCATION ], undefined, undefined, meta)
20
+ const loc = (location instanceof URL) ? location.href : location
21
+
22
+ send_no_body(stream, HTTP_STATUS_TEMPORARY_REDIRECT, {
23
+ [HTTP2_HEADER_LOCATION]: loc
24
+ }, [ HTTP2_HEADER_LOCATION ], meta)
23
25
  }
@@ -1,4 +1,4 @@
1
- import http2 from 'node:http2'
1
+ import http2 from 'node:http2'
2
2
 
3
3
  import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
4
4
  import { send } from '../send-util.js'
@@ -14,6 +14,5 @@ const { HTTP_STATUS_BAD_REQUEST } = http2.constants
14
14
  * @param {Metadata} meta
15
15
  */
16
16
  export function sendBadRequest(stream, message, meta) {
17
- send(stream, HTTP_STATUS_BAD_REQUEST, {
18
- }, [ ], CONTENT_TYPE_TEXT, message, meta)
17
+ send(stream, HTTP_STATUS_BAD_REQUEST, {}, [], CONTENT_TYPE_TEXT, message, meta)
19
18
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,5 +12,5 @@ const { HTTP_STATUS_CONFLICT } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendConflict(stream, meta) {
15
- send(stream, HTTP_STATUS_CONFLICT, {}, [], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_CONFLICT, {}, [], meta)
16
16
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,5 +12,5 @@ const { HTTP_STATUS_PAYLOAD_TOO_LARGE } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendContentTooLarge(stream, meta) {
15
- send(stream, HTTP_STATUS_PAYLOAD_TOO_LARGE, {}, [], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_PAYLOAD_TOO_LARGE, {}, [], meta)
16
16
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,6 +12,6 @@ const { HTTP_STATUS_FORBIDDEN} = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendForbidden(stream, meta) {
15
- send(stream, HTTP_STATUS_FORBIDDEN, {
16
- }, [], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_FORBIDDEN, {
16
+ }, [], meta)
17
17
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,5 +12,5 @@ const { HTTP_STATUS_GONE } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendGone(stream, meta) {
15
- send(stream, HTTP_STATUS_GONE, {}, [], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_GONE, {}, [], meta)
16
16
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,5 +12,5 @@ const { HTTP_STATUS_TEAPOT } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendImATeapot(stream, meta) {
15
- send(stream, HTTP_STATUS_TEAPOT, {}, [], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_TEAPOT, {}, [], meta)
16
16
  }
@@ -8,21 +8,12 @@ import { send } from '../send-util.js'
8
8
 
9
9
  const { HTTP_STATUS_NOT_ACCEPTABLE } = http2.constants
10
10
 
11
- /**
12
- * @param {ServerHttp2Stream} stream
13
- * @param {Array<string>|string} supportedTypes
14
- * @param {Metadata} meta
15
- */
16
- export function sendNotAcceptable(stream, supportedTypes, meta) {
17
- _sendNotAcceptable(stream, { supportedTypes }, meta)
18
- }
19
-
20
11
  /**
21
12
  * @param {ServerHttp2Stream} stream
22
13
  * @param {Pick<SendInfo, 'supportedTypes'>} info
23
14
  * @param {Metadata} meta
24
15
  */
25
- export function _sendNotAcceptable(stream, info, meta) {
16
+ export function sendNotAcceptable(stream, info, meta) {
26
17
  const { supportedTypes } = info
27
18
 
28
19
  const supportedTypesList = Array.isArray(supportedTypes) ? supportedTypes : [ supportedTypes ]
@@ -33,6 +24,6 @@ export function _sendNotAcceptable(stream, info, meta) {
33
24
  {},
34
25
  [],
35
26
  has ? CONTENT_TYPE_JSON : undefined,
36
- has ? JSON.stringify(supportedTypes) : undefined,
27
+ has ? JSON.stringify({ supportedTypes: supportedTypesList }) : undefined,
37
28
  meta)
38
29
  }
@@ -1,6 +1,7 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { COMMON_LIST_VALUE_JOINER_COMMA } from '../../defs.js'
4
+ import { send_no_body } from '../send-util.js'
4
5
 
5
6
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
7
  /** @import { SendInfo, Metadata } from '../../defs.js' */
@@ -11,24 +12,15 @@ const {
11
12
 
12
13
  const { HTTP2_HEADER_ALLOW } = http2.constants
13
14
 
14
- /**
15
- * @param {ServerHttp2Stream} stream
16
- * @param {Array<string>} supportedMethods
17
- * @param {Metadata} meta
18
- */
19
- export function sendNotAllowed(stream, supportedMethods, meta) {
20
- _sendNotAllowed(stream, { supportedMethods }, meta)
21
- }
22
-
23
15
  /**
24
16
  * @param {ServerHttp2Stream} stream
25
17
  * @param {Pick<SendInfo, 'supportedMethods'>} info
26
18
  * @param {Metadata} meta
27
19
  */
28
- export function _sendNotAllowed(stream, info, meta) {
20
+ export function sendNotAllowed(stream, info, meta) {
29
21
  const { supportedMethods } = info
30
22
 
31
- send(stream, HTTP_STATUS_METHOD_NOT_ALLOWED, {
32
- [HTTP2_HEADER_ALLOW]: supportedMethods.join(',')
33
- }, [ HTTP2_HEADER_ALLOW ], undefined, undefined, meta)
23
+ send_no_body(stream, HTTP_STATUS_METHOD_NOT_ALLOWED, {
24
+ [HTTP2_HEADER_ALLOW]: supportedMethods.join(COMMON_LIST_VALUE_JOINER_COMMA)
25
+ }, [ HTTP2_HEADER_ALLOW ], meta)
34
26
  }
@@ -1,6 +1,6 @@
1
- import http2 from 'node:http2'
1
+ import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,6 +12,6 @@ const { HTTP_STATUS_PAYMENT_REQUIRED } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendPaymentRequired(stream, meta) {
15
- send(stream, HTTP_STATUS_PAYMENT_REQUIRED, {
16
- }, [ ], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_PAYMENT_REQUIRED, {
16
+ }, [ ], meta)
17
17
  }
@@ -1,11 +1,10 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
3
  import { Conditional } from '../../headers/conditional.js'
4
- import { send } from '../send-util.js'
4
+ import { send_no_body } from '../send-util.js'
5
5
 
6
6
  /** @import { ServerHttp2Stream } from 'node:http2' */
7
7
  /** @import { SendContent, Metadata } from '../../defs.js' */
8
- /** @import { EtagItem ,IMFFixDateInput } from '../../headers/conditional.js' */
9
8
 
10
9
  const {
11
10
  HTTP2_HEADER_ETAG,
@@ -14,32 +13,19 @@ const {
14
13
 
15
14
  const { HTTP_STATUS_PRECONDITION_FAILED } = http2.constants
16
15
 
17
- /**
18
- * @param {ServerHttp2Stream} stream
19
- * @param {EtagItem|undefined} etag
20
- * @param {IMFFixDateInput|string|undefined} lastModified
21
- * @param {Metadata} meta
22
- */
23
- export function sendPreconditionFailed(stream, etag, lastModified, meta) {
24
- _sendPreconditionFailed(stream, {
25
- etag,
26
- lastModified
27
- }, meta)
28
- }
29
-
30
16
  /**
31
17
  * @param {ServerHttp2Stream} stream
32
18
  * @param {Pick<SendContent, 'etag' | 'lastModified'>} content
33
19
  * @param {Metadata} meta
34
20
  */
35
- export function _sendPreconditionFailed(stream, content, meta) {
21
+ export function sendPreconditionFailed(stream, content, meta) {
36
22
  const {
37
23
  etag,
38
24
  lastModified
39
25
  } = content
40
26
 
41
- send(stream, HTTP_STATUS_PRECONDITION_FAILED, {
27
+ send_no_body(stream, HTTP_STATUS_PRECONDITION_FAILED, {
42
28
  [HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
43
29
  [HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified)
44
- }, [], undefined, undefined, meta)
30
+ }, [], meta)
45
31
  }
@@ -1,7 +1,7 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
3
  import { CONTENT_RANGE_UNKNOWN, ContentRange } from '../../headers/content-range.js'
4
- import { send } from '../send-util.js'
4
+ import { send_no_body } from '../send-util.js'
5
5
 
6
6
  /** @import { ServerHttp2Stream } from 'node:http2' */
7
7
  /** @import { SendContent, Metadata } from '../../defs.js' */
@@ -13,27 +13,18 @@ const {
13
13
 
14
14
  const { HTTP_STATUS_RANGE_NOT_SATISFIABLE } = http2.constants
15
15
 
16
- /**
17
- * @param {ServerHttp2Stream} stream
18
- * @param {ContentRangeDirective} rangeDirective
19
- * @param {Metadata} meta
20
- */
21
- export function sendRangeNotSatisfiable(stream, rangeDirective, meta) {
22
- _sendRangeNotSatisfiable(stream, { rangeDirective }, meta)
23
- }
24
-
25
16
  /**
26
17
  * @param {ServerHttp2Stream} stream
27
18
  * @param {Pick<SendContent, 'rangeDirective'>} content
28
19
  * @param {Metadata} meta
29
20
  */
30
- export function _sendRangeNotSatisfiable(stream, content, meta) {
21
+ export function sendRangeNotSatisfiable(stream, content, meta) {
31
22
  const { rangeDirective } = content
32
23
 
33
24
  /** @type {ContentRangeDirective} */
34
25
  const invalidRange = { size: rangeDirective.size, range: CONTENT_RANGE_UNKNOWN }
35
26
 
36
- send(stream, HTTP_STATUS_RANGE_NOT_SATISFIABLE, {
27
+ send_no_body(stream, HTTP_STATUS_RANGE_NOT_SATISFIABLE, {
37
28
  [HTTP2_HEADER_CONTENT_RANGE]: ContentRange.encode(invalidRange)
38
- }, [ HTTP2_HEADER_CONTENT_RANGE ], undefined, undefined, meta)
29
+ }, [ HTTP2_HEADER_CONTENT_RANGE ], meta)
39
30
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -16,7 +16,7 @@ const { HTTP2_HEADER_CONNECTION } = http2.constants
16
16
  * @param {Metadata} meta
17
17
  */
18
18
  export function sendTimeout(stream, meta) {
19
- send(stream, HTTP_STATUS_REQUEST_TIMEOUT, {
19
+ send_no_body(stream, HTTP_STATUS_REQUEST_TIMEOUT, {
20
20
  [HTTP2_HEADER_CONNECTION]: 'close'
21
- }, [], undefined, undefined, meta)
21
+ }, [], meta)
22
22
  }
@@ -1,17 +1,15 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
4
3
  import {
5
4
  HTTP_HEADER_RATE_LIMIT,
6
5
  HTTP_HEADER_RATE_LIMIT_POLICY,
7
6
  RateLimit,
8
7
  RateLimitPolicy
9
8
  } from '../../headers/rate-limit.js'
10
- import { send } from '../send-util.js'
9
+ import { send_no_body } from '../send-util.js'
11
10
 
12
11
  /** @import { ServerHttp2Stream } from 'node:http2' */
13
12
  /** @import { SendInfo, Metadata } from '../../defs.js' */
14
- /** @import { RateLimitInfo, RateLimitPolicyInfo } from '../../headers/rate-limit.js' */
15
13
 
16
14
  const {
17
15
  HTTP2_HEADER_RETRY_AFTER
@@ -19,31 +17,18 @@ const {
19
17
 
20
18
  const { HTTP_STATUS_TOO_MANY_REQUESTS } = http2.constants
21
19
 
22
- /**
23
- * @param {ServerHttp2Stream} stream
24
- * @param {RateLimitInfo} limitInfo
25
- * @param {Array<RateLimitPolicyInfo>} policies
26
- * @param {Metadata} meta
27
- */
28
- export function sendTooManyRequests(stream, limitInfo, policies, meta) {
29
- _sendTooManyRequests(stream, {
30
- limitInfo,
31
- policies
32
- }, meta)
33
- }
34
-
35
20
  /**
36
21
  * @param {ServerHttp2Stream} stream
37
22
  * @param {Pick<SendInfo, 'limitInfo' | 'policies'>} info
38
23
  * @param {Metadata} meta
39
24
  */
40
- export function _sendTooManyRequests(stream, info, meta) {
25
+ export function sendTooManyRequests(stream, info, meta) {
41
26
  const {
42
27
  limitInfo,
43
28
  policies
44
29
  } = info
45
30
 
46
- send(stream, HTTP_STATUS_TOO_MANY_REQUESTS, {
31
+ send_no_body(stream, HTTP_STATUS_TOO_MANY_REQUESTS, {
47
32
  [HTTP2_HEADER_RETRY_AFTER]: `${limitInfo.resetSeconds}`,
48
33
  [HTTP_HEADER_RATE_LIMIT]: RateLimit.from(limitInfo),
49
34
  [HTTP_HEADER_RATE_LIMIT_POLICY]: RateLimitPolicy.from(...policies)
@@ -53,7 +38,5 @@ export function _sendTooManyRequests(stream, info, meta) {
53
38
  HTTP_HEADER_RATE_LIMIT,
54
39
  HTTP_HEADER_RATE_LIMIT_POLICY
55
40
  ],
56
- CONTENT_TYPE_TEXT,
57
- `Retry After ${limitInfo.resetSeconds} Seconds`,
58
41
  meta)
59
42
  }
@@ -1,7 +1,7 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
3
  import { Challenge } from '../../headers/www-authenticate.js'
4
- import { send } from '../send-util.js'
4
+ import { send_no_body } from '../send-util.js'
5
5
 
6
6
  /** @import { ServerHttp2Stream } from 'node:http2' */
7
7
  /** @import { Metadata } from '../../defs.js' */
@@ -19,7 +19,7 @@ const { HTTP_STATUS_UNAUTHORIZED } = http2.constants
19
19
  * @param {Metadata} meta
20
20
  */
21
21
  export function sendUnauthorized(stream, challenge, meta) {
22
- send(stream, HTTP_STATUS_UNAUTHORIZED, {
23
- [HTTP2_HEADER_WWW_AUTHENTICATE]: challenge?.map(Challenge.encode), // todo stringify ?
24
- }, [ HTTP2_HEADER_WWW_AUTHENTICATE ], undefined, undefined, meta)
22
+ send_no_body(stream, HTTP_STATUS_UNAUTHORIZED, {
23
+ [HTTP2_HEADER_WWW_AUTHENTICATE]: Challenge.encode(challenge),
24
+ }, [ HTTP2_HEADER_WWW_AUTHENTICATE ], meta)
25
25
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_no_body } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,5 +12,5 @@ const { HTTP_STATUS_UNPROCESSABLE_ENTITY } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendUnprocessable(stream, meta) {
15
- send(stream, HTTP_STATUS_UNPROCESSABLE_ENTITY, {}, [], undefined, undefined, meta)
15
+ send_no_body(stream, HTTP_STATUS_UNPROCESSABLE_ENTITY, {}, [], meta)
16
16
  }
@@ -1,7 +1,12 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { HTTP_HEADER_ACCEPT_PATCH, HTTP_HEADER_ACCEPT_POST, HTTP_HEADER_ACCEPT_QUERY } from '../../defs.js'
4
- import { send } from '../send-util.js'
3
+ import {
4
+ COMMON_LIST_VALUE_JOINER_COMMA,
5
+ HTTP_HEADER_ACCEPT_PATCH,
6
+ HTTP_HEADER_ACCEPT_POST,
7
+ HTTP_HEADER_ACCEPT_QUERY
8
+ } from '../../defs.js'
9
+ import { send_no_body } from '../send-util.js'
5
10
 
6
11
  /** @import { ServerHttp2Stream } from 'node:http2' */
7
12
  /** @import { SendInfo, Metadata } from '../../defs.js' */
@@ -10,40 +15,28 @@ const { HTTP2_METHOD_POST, HTTP2_METHOD_PATCH } = http2.constants
10
15
 
11
16
  const { HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE } = http2.constants
12
17
 
13
- /**
14
- * @param {ServerHttp2Stream} stream
15
- * @param {Array<string>|string} acceptableMediaType
16
- * @param {Array<string>|undefined} supportedQueryTypes
17
- * @param {Metadata} meta
18
- */
19
- export function sendUnsupportedMediaType(stream, acceptableMediaType, supportedQueryTypes, meta) {
20
- _sendUnsupportedMediaType(stream, {
21
- acceptableMediaType,
22
- supportedQueryTypes
23
- }, meta)
24
- }
25
-
26
18
  /**
27
19
  * @param {ServerHttp2Stream} stream
28
20
  * @param {Pick<SendInfo, 'acceptableMediaType' | 'supportedQueryTypes'>} info
29
21
  * @param {Metadata} meta
30
22
  */
31
- export function _sendUnsupportedMediaType(stream, info, meta) {
23
+ export function sendUnsupportedMediaType(stream, info, meta) {
32
24
  const {
33
25
  supportedQueryTypes,
34
26
  acceptableMediaType
35
27
  } = info
36
28
 
37
- const supportsQuery = supportedQueryTypes !== undefined && supportedQueryTypes.length > 0
38
- const exposedHeaders = supportsQuery ? [ HTTP_HEADER_ACCEPT_QUERY, HTTP_HEADER_ACCEPT_POST ] : [ HTTP_HEADER_ACCEPT_POST ]
39
-
40
29
  const method = HTTP2_METHOD_POST // todo pass in as parameter or split acceptable to post and patch types
41
30
  const acceptable = Array.isArray(acceptableMediaType) ? acceptableMediaType : [ acceptableMediaType ] // todo undefined creates array of one item
42
31
  const acceptHeader = (method === HTTP2_METHOD_POST) ? HTTP_HEADER_ACCEPT_POST : HTTP_HEADER_ACCEPT_PATCH
43
- const acceptValue = ((method === HTTP2_METHOD_POST) || (method === HTTP2_METHOD_PATCH)) ? acceptable.join(',') : undefined
32
+ const acceptValue = ((method === HTTP2_METHOD_POST) || (method === HTTP2_METHOD_PATCH)) ? acceptable.join(COMMON_LIST_VALUE_JOINER_COMMA) : undefined
33
+
34
+ const supportsQuery = supportedQueryTypes !== undefined && supportedQueryTypes.length > 0
35
+ const exposedHeaders = supportsQuery ? [ HTTP_HEADER_ACCEPT_QUERY, acceptHeader ] : [ acceptHeader ]
36
+
44
37
 
45
- send(stream, HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, {
38
+ send_no_body(stream, HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, {
46
39
  [acceptHeader]: acceptValue,
47
- [HTTP_HEADER_ACCEPT_QUERY]: supportedQueryTypes?.join(',')
48
- }, exposedHeaders, undefined, undefined, meta)
40
+ [HTTP_HEADER_ACCEPT_QUERY]: supportedQueryTypes?.join(COMMON_LIST_VALUE_JOINER_COMMA)
41
+ }, exposedHeaders, meta)
49
42
  }
@@ -1,7 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
4
- import { send } from '../send-util.js'
3
+ import { send_error } from '../send-util.js'
5
4
 
6
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
7
6
  /** @import { Metadata } from '../../defs.js' */
@@ -14,5 +13,5 @@ const { HTTP_STATUS_INTERNAL_SERVER_ERROR } = http2.constants
14
13
  * @param {Metadata} meta
15
14
  */
16
15
  export function sendError(stream, message, meta) {
17
- send(stream, HTTP_STATUS_INTERNAL_SERVER_ERROR, {}, [], CONTENT_TYPE_TEXT, message, meta)
16
+ send_error(stream, HTTP_STATUS_INTERNAL_SERVER_ERROR, message, undefined, meta)
18
17
  }
@@ -1,6 +1,6 @@
1
1
  import http2 from 'node:http2'
2
2
 
3
- import { send } from '../send-util.js'
3
+ import { send_error } from '../send-util.js'
4
4
 
5
5
  /** @import { ServerHttp2Stream } from 'node:http2' */
6
6
  /** @import { Metadata } from '../../defs.js' */
@@ -12,5 +12,5 @@ const { HTTP_STATUS_INSUFFICIENT_STORAGE } = http2.constants
12
12
  * @param {Metadata} meta
13
13
  */
14
14
  export function sendInsufficientStorage(stream, meta) {
15
- send(stream, HTTP_STATUS_INSUFFICIENT_STORAGE, {}, [], undefined, undefined, meta)
15
+ send_error(stream, HTTP_STATUS_INSUFFICIENT_STORAGE, 'Insufficient Storage', undefined, meta)
16
16
  }