@johntalton/http-util 5.1.6 → 6.1.0

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 (84) hide show
  1. package/README.md +54 -7
  2. package/package.json +26 -6
  3. package/src/body.js +8 -8
  4. package/src/{response/defs.js → defs.js} +35 -1
  5. package/src/{accept-encoding.js → headers/accept-encoding.js} +11 -14
  6. package/src/{accept-language.js → headers/accept-language.js} +14 -9
  7. package/src/headers/accept.js +86 -0
  8. package/src/{cache-control.js → headers/cache-control.js} +0 -6
  9. package/src/{clear-site-data.js → headers/clear-site-data.js} +4 -10
  10. package/src/headers/client-hints.js +88 -0
  11. package/src/{conditional.js → headers/conditional.js} +190 -117
  12. package/src/headers/content-disposition.js +44 -0
  13. package/src/{content-range.js → headers/content-range.js} +1 -18
  14. package/src/headers/content-type.js +101 -0
  15. package/src/{forwarded.js → headers/forwarded.js} +8 -56
  16. package/src/{index.js → headers/index.js} +4 -2
  17. package/src/headers/link.js +34 -0
  18. package/src/{multipart.js → headers/multipart.js} +22 -13
  19. package/src/{preference.js → headers/preference.js} +3 -58
  20. package/src/{range.js → headers/range.js} +4 -32
  21. package/src/{rate-limit.js → headers/rate-limit.js} +6 -1
  22. package/src/{server-timing.js → headers/server-timing.js} +3 -16
  23. package/src/headers/strict-transport-security.js +39 -0
  24. package/src/{accept-util.js → headers/util/accept-util.js} +8 -14
  25. package/src/headers/util/index.js +7 -0
  26. package/src/headers/util/kvp.js +79 -0
  27. package/src/headers/util/mime.js +77 -0
  28. package/src/headers/util/whitespace.js +8 -0
  29. package/src/{www-authenticate.js → headers/www-authenticate.js} +1 -1
  30. package/src/response/{accepted.js → 2xx/accepted.js} +2 -2
  31. package/src/response/2xx/bytes.js +62 -0
  32. package/src/response/2xx/created.js +49 -0
  33. package/src/response/2xx/json.js +60 -0
  34. package/src/response/2xx/no-content.js +45 -0
  35. package/src/response/2xx/partial-content.js +101 -0
  36. package/src/response/{preflight.js → 2xx/preflight.js} +29 -10
  37. package/src/response/{sse.js → 2xx/sse.js} +2 -2
  38. package/src/response/{trace.js → 2xx/trace.js} +3 -3
  39. package/src/response/3xx/found.js +23 -0
  40. package/src/response/{moved-permanently.js → 3xx/moved-permanently.js} +2 -2
  41. package/src/response/{multiple-choices.js → 3xx/multiple-choices.js} +2 -3
  42. package/src/response/3xx/not-modified.js +59 -0
  43. package/src/response/{permanent-redirect.js → 3xx/permanent-redirect.js} +2 -2
  44. package/src/response/{see-other.js → 3xx/see-other.js} +2 -2
  45. package/src/response/{temporary-redirect.js → 3xx/temporary-redirect.js} +2 -2
  46. package/src/response/4xx/bad-request.js +19 -0
  47. package/src/response/{conflict.js → 4xx/conflict.js} +2 -2
  48. package/src/response/{content-too-large.js → 4xx/content-too-large.js} +2 -2
  49. package/src/response/{forbidden.js → 4xx/forbidden.js} +3 -2
  50. package/src/response/{gone.js → 4xx/gone.js} +2 -2
  51. package/src/response/{im-a-teapot.js → 4xx/im-a-teapot.js} +2 -2
  52. package/src/response/{not-acceptable.js → 4xx/not-acceptable.js} +14 -3
  53. package/src/response/4xx/not-allowed.js +34 -0
  54. package/src/response/{not-found.js → 4xx/not-found.js} +3 -3
  55. package/src/response/4xx/payment-required.js +17 -0
  56. package/src/response/4xx/precondition-failed.js +45 -0
  57. package/src/response/{range-not-satisfiable.js → 4xx/range-not-satisfiable.js} +15 -4
  58. package/src/response/{timeout.js → 4xx/timeout.js} +2 -2
  59. package/src/response/{too-many-requests.js → 4xx/too-many-requests.js} +22 -5
  60. package/src/response/{unauthorized.js → 4xx/unauthorized.js} +5 -5
  61. package/src/response/{unprocessable.js → 4xx/unprocessable.js} +2 -2
  62. package/src/response/{unsupported-media.js → 4xx/unsupported-media.js} +21 -4
  63. package/src/response/{error.js → 5xx/error.js} +3 -3
  64. package/src/response/{insufficient-storage.js → 5xx/insufficient-storage.js} +2 -2
  65. package/src/response/{not-implemented.js → 5xx/not-implemented.js} +4 -4
  66. package/src/response/{unavailable.js → 5xx/unavailable.js} +16 -4
  67. package/src/response/header-util.js +2 -2
  68. package/src/response/index.js +39 -35
  69. package/src/response/response.js +40 -34
  70. package/src/response/send-util.js +32 -21
  71. package/src/accept.js +0 -122
  72. package/src/content-disposition.js +0 -57
  73. package/src/content-type.js +0 -148
  74. package/src/link.js +0 -35
  75. package/src/response/bytes.js +0 -27
  76. package/src/response/created.js +0 -28
  77. package/src/response/json.js +0 -28
  78. package/src/response/no-content.js +0 -25
  79. package/src/response/not-allowed.js +0 -23
  80. package/src/response/not-modified.js +0 -35
  81. package/src/response/partial-content.js +0 -71
  82. package/src/response/precondition-failed.js +0 -16
  83. /package/src/{fetch-metadata.js → headers/fetch-metadata.js} +0 -0
  84. /package/src/{quote.js → headers/util/quote.js} +0 -0
@@ -1,71 +0,0 @@
1
- import http2 from 'node:http2'
2
-
3
- import { MIME_TYPE_MULTIPART_RANGE } from '../content-type.js'
4
- import { Multipart } from '../multipart.js'
5
- import { RANGE_UNITS_BYTES } from "./defs.js"
6
- import { send_bytes } from './send-util.js'
7
-
8
- /** @import { ServerHttp2Stream } from 'node:http2' */
9
- /** @import { Metadata } from './defs.js' */
10
- /** @import { EtagItem } from '../conditional.js' */
11
- /** @import { CacheControlOptions } from '../cache-control.js' */
12
- /** @import { ContentRangeDirective } from '../content-range.js' */
13
- /** @import { SendBody } from './send-util.js' */
14
-
15
- const { HTTP_STATUS_PARTIAL_CONTENT } = http2.constants
16
-
17
- /**
18
- * @template T
19
- * @typedef {[ T, ...T[] ]} NonEmptyArray
20
- */
21
-
22
- /**
23
- * @typedef {Object} PartialBytes
24
- * @property {SendBody} obj
25
- * @property {ContentRangeDirective} range
26
- */
27
-
28
- /**
29
- * @param {ServerHttp2Stream} stream
30
- * @param {string} contentType
31
- * @param {NonEmptyArray<PartialBytes>|PartialBytes} objs
32
- * @param {number|undefined} contentLength
33
- * @param {string|undefined} encoding
34
- * @param {EtagItem|undefined} etag
35
- * @param {number|undefined} age
36
- * @param {CacheControlOptions} cacheControl
37
- * @param {Metadata} meta
38
- */
39
- export function sendPartialContent(stream, contentType, objs, contentLength, encoding, etag, age, cacheControl, meta) {
40
- const acceptRanges = RANGE_UNITS_BYTES
41
- const supportedQueryTypes = undefined
42
-
43
- if(Array.isArray(objs) && objs.length > 1) {
44
- // send using multipart bytes
45
- const boundary = 'PARTIAL_CONTENT_BOUNDARY' // todo make unique for content
46
- const obj = Multipart.encode_Bytes(contentType, objs, contentLength, boundary)
47
-
48
- const multipartContentType = `${MIME_TYPE_MULTIPART_RANGE}; boundary=${boundary}`
49
-
50
- send_bytes(
51
- stream,
52
- HTTP_STATUS_PARTIAL_CONTENT,
53
- multipartContentType,
54
- obj,
55
- undefined,
56
- undefined,
57
- encoding,
58
- etag,
59
- age,
60
- cacheControl,
61
- acceptRanges,
62
- supportedQueryTypes,
63
- meta)
64
-
65
- return
66
- }
67
-
68
- // single range, send as regular object
69
- const obj = Array.isArray(objs) ? objs[0] : objs
70
- send_bytes(stream, HTTP_STATUS_PARTIAL_CONTENT, contentType, obj.obj, obj.range, undefined, encoding, etag, age, cacheControl, acceptRanges, supportedQueryTypes, meta)
71
- }
@@ -1,16 +0,0 @@
1
- import http2 from 'node:http2'
2
-
3
- import { send } from './send-util.js'
4
-
5
- /** @import { ServerHttp2Stream } from 'node:http2' */
6
- /** @import { Metadata } from './defs.js' */
7
-
8
- const { HTTP_STATUS_PRECONDITION_FAILED } = http2.constants
9
-
10
- /**
11
- * @param {ServerHttp2Stream} stream
12
- * @param {Metadata} meta
13
- */
14
- export function sendPreconditionFailed(stream, meta) {
15
- send(stream, HTTP_STATUS_PRECONDITION_FAILED, {}, [], undefined, undefined, meta)
16
- }
File without changes