@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.
- package/README.md +54 -7
- package/package.json +26 -6
- package/src/body.js +8 -8
- package/src/{response/defs.js → defs.js} +35 -1
- package/src/{accept-encoding.js → headers/accept-encoding.js} +11 -14
- package/src/{accept-language.js → headers/accept-language.js} +14 -9
- package/src/headers/accept.js +86 -0
- package/src/{cache-control.js → headers/cache-control.js} +0 -6
- package/src/{clear-site-data.js → headers/clear-site-data.js} +4 -10
- package/src/headers/client-hints.js +88 -0
- package/src/{conditional.js → headers/conditional.js} +190 -117
- package/src/headers/content-disposition.js +44 -0
- package/src/{content-range.js → headers/content-range.js} +1 -18
- package/src/headers/content-type.js +101 -0
- package/src/{forwarded.js → headers/forwarded.js} +8 -56
- package/src/{index.js → headers/index.js} +4 -2
- package/src/headers/link.js +34 -0
- package/src/{multipart.js → headers/multipart.js} +22 -13
- package/src/{preference.js → headers/preference.js} +3 -58
- package/src/{range.js → headers/range.js} +4 -32
- package/src/{rate-limit.js → headers/rate-limit.js} +6 -1
- package/src/{server-timing.js → headers/server-timing.js} +3 -16
- package/src/headers/strict-transport-security.js +39 -0
- package/src/{accept-util.js → headers/util/accept-util.js} +8 -14
- package/src/headers/util/index.js +7 -0
- package/src/headers/util/kvp.js +79 -0
- package/src/headers/util/mime.js +77 -0
- package/src/headers/util/whitespace.js +8 -0
- package/src/{www-authenticate.js → headers/www-authenticate.js} +1 -1
- package/src/response/{accepted.js → 2xx/accepted.js} +2 -2
- package/src/response/2xx/bytes.js +62 -0
- package/src/response/2xx/created.js +49 -0
- package/src/response/2xx/json.js +60 -0
- package/src/response/2xx/no-content.js +45 -0
- package/src/response/2xx/partial-content.js +101 -0
- package/src/response/{preflight.js → 2xx/preflight.js} +29 -10
- package/src/response/{sse.js → 2xx/sse.js} +2 -2
- package/src/response/{trace.js → 2xx/trace.js} +3 -3
- package/src/response/3xx/found.js +23 -0
- package/src/response/{moved-permanently.js → 3xx/moved-permanently.js} +2 -2
- package/src/response/{multiple-choices.js → 3xx/multiple-choices.js} +2 -3
- package/src/response/3xx/not-modified.js +59 -0
- package/src/response/{permanent-redirect.js → 3xx/permanent-redirect.js} +2 -2
- package/src/response/{see-other.js → 3xx/see-other.js} +2 -2
- package/src/response/{temporary-redirect.js → 3xx/temporary-redirect.js} +2 -2
- package/src/response/4xx/bad-request.js +19 -0
- package/src/response/{conflict.js → 4xx/conflict.js} +2 -2
- package/src/response/{content-too-large.js → 4xx/content-too-large.js} +2 -2
- package/src/response/{forbidden.js → 4xx/forbidden.js} +3 -2
- package/src/response/{gone.js → 4xx/gone.js} +2 -2
- package/src/response/{im-a-teapot.js → 4xx/im-a-teapot.js} +2 -2
- package/src/response/{not-acceptable.js → 4xx/not-acceptable.js} +14 -3
- package/src/response/4xx/not-allowed.js +34 -0
- package/src/response/{not-found.js → 4xx/not-found.js} +3 -3
- package/src/response/4xx/payment-required.js +17 -0
- package/src/response/4xx/precondition-failed.js +45 -0
- package/src/response/{range-not-satisfiable.js → 4xx/range-not-satisfiable.js} +15 -4
- package/src/response/{timeout.js → 4xx/timeout.js} +2 -2
- package/src/response/{too-many-requests.js → 4xx/too-many-requests.js} +22 -5
- package/src/response/{unauthorized.js → 4xx/unauthorized.js} +5 -5
- package/src/response/{unprocessable.js → 4xx/unprocessable.js} +2 -2
- package/src/response/{unsupported-media.js → 4xx/unsupported-media.js} +21 -4
- package/src/response/{error.js → 5xx/error.js} +3 -3
- package/src/response/{insufficient-storage.js → 5xx/insufficient-storage.js} +2 -2
- package/src/response/{not-implemented.js → 5xx/not-implemented.js} +4 -4
- package/src/response/{unavailable.js → 5xx/unavailable.js} +16 -4
- package/src/response/header-util.js +2 -2
- package/src/response/index.js +39 -35
- package/src/response/response.js +40 -34
- package/src/response/send-util.js +32 -21
- package/src/accept.js +0 -122
- package/src/content-disposition.js +0 -57
- package/src/content-type.js +0 -148
- package/src/link.js +0 -35
- package/src/response/bytes.js +0 -27
- package/src/response/created.js +0 -28
- package/src/response/json.js +0 -28
- package/src/response/no-content.js +0 -25
- package/src/response/not-allowed.js +0 -23
- package/src/response/not-modified.js +0 -35
- package/src/response/partial-content.js +0 -71
- package/src/response/precondition-failed.js +0 -16
- /package/src/{fetch-metadata.js → headers/fetch-metadata.js} +0 -0
- /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
|
|
File without changes
|