@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,10 +1,10 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { CONTENT_TYPE_TEXT } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
7
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
8
8
|
|
|
9
9
|
const { HTTP_STATUS_NOT_FOUND } = http2.constants
|
|
10
10
|
|
|
@@ -0,0 +1,17 @@
|
|
|
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_PAYMENT_REQUIRED } = http2.constants
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {ServerHttp2Stream} stream
|
|
12
|
+
* @param {Metadata} meta
|
|
13
|
+
*/
|
|
14
|
+
export function sendPaymentRequired(stream, meta) {
|
|
15
|
+
send(stream, HTTP_STATUS_PAYMENT_REQUIRED, {
|
|
16
|
+
}, [ ], undefined, undefined, meta)
|
|
17
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import http2 from 'node:http2'
|
|
2
|
+
|
|
3
|
+
import { Conditional } from '../../headers/conditional.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
|
+
|
|
6
|
+
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
+
/** @import { SendContent, Metadata } from '../../defs.js' */
|
|
8
|
+
/** @import { EtagItem ,IMFFixDateInput } from '../../headers/conditional.js' */
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
HTTP2_HEADER_ETAG,
|
|
12
|
+
HTTP2_HEADER_LAST_MODIFIED
|
|
13
|
+
} = http2.constants
|
|
14
|
+
|
|
15
|
+
const { HTTP_STATUS_PRECONDITION_FAILED } = http2.constants
|
|
16
|
+
|
|
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
|
+
/**
|
|
31
|
+
* @param {ServerHttp2Stream} stream
|
|
32
|
+
* @param {Pick<SendContent, 'etag' | 'lastModified'>} content
|
|
33
|
+
* @param {Metadata} meta
|
|
34
|
+
*/
|
|
35
|
+
export function _sendPreconditionFailed(stream, content, meta) {
|
|
36
|
+
const {
|
|
37
|
+
etag,
|
|
38
|
+
lastModified
|
|
39
|
+
} = content
|
|
40
|
+
|
|
41
|
+
send(stream, HTTP_STATUS_PRECONDITION_FAILED, {
|
|
42
|
+
[HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
|
|
43
|
+
[HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified)
|
|
44
|
+
}, [], undefined, undefined, meta)
|
|
45
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { CONTENT_RANGE_UNKNOWN, ContentRange } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { CONTENT_RANGE_UNKNOWN, ContentRange } from '../../headers/content-range.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
8
|
-
/** @import { ContentRangeDirective} from '
|
|
7
|
+
/** @import { SendContent, Metadata } from '../../defs.js' */
|
|
8
|
+
/** @import { ContentRangeDirective} from '../../headers/content-range.js' */
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
11
|
HTTP2_HEADER_CONTENT_RANGE
|
|
@@ -19,6 +19,17 @@ const { HTTP_STATUS_RANGE_NOT_SATISFIABLE } = http2.constants
|
|
|
19
19
|
* @param {Metadata} meta
|
|
20
20
|
*/
|
|
21
21
|
export function sendRangeNotSatisfiable(stream, rangeDirective, meta) {
|
|
22
|
+
_sendRangeNotSatisfiable(stream, { rangeDirective }, meta)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {ServerHttp2Stream} stream
|
|
27
|
+
* @param {Pick<SendContent, 'rangeDirective'>} content
|
|
28
|
+
* @param {Metadata} meta
|
|
29
|
+
*/
|
|
30
|
+
export function _sendRangeNotSatisfiable(stream, content, meta) {
|
|
31
|
+
const { rangeDirective } = content
|
|
32
|
+
|
|
22
33
|
/** @type {ContentRangeDirective} */
|
|
23
34
|
const invalidRange = { size: rangeDirective.size, range: CONTENT_RANGE_UNKNOWN }
|
|
24
35
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { send } from '
|
|
3
|
+
import { send } from '../send-util.js'
|
|
4
4
|
|
|
5
5
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
6
|
-
/** @import { Metadata } from '
|
|
6
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
HTTP_STATUS_REQUEST_TIMEOUT
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { CONTENT_TYPE_TEXT } from '
|
|
3
|
+
import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
|
|
4
4
|
import {
|
|
5
5
|
HTTP_HEADER_RATE_LIMIT,
|
|
6
6
|
HTTP_HEADER_RATE_LIMIT_POLICY,
|
|
7
7
|
RateLimit,
|
|
8
8
|
RateLimitPolicy
|
|
9
|
-
} from '
|
|
10
|
-
import { send } from '
|
|
9
|
+
} from '../../headers/rate-limit.js'
|
|
10
|
+
import { send } from '../send-util.js'
|
|
11
11
|
|
|
12
12
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
13
|
-
/** @import { Metadata } from '
|
|
14
|
-
/** @import { RateLimitInfo, RateLimitPolicyInfo } from '
|
|
13
|
+
/** @import { SendInfo, Metadata } from '../../defs.js' */
|
|
14
|
+
/** @import { RateLimitInfo, RateLimitPolicyInfo } from '../../headers/rate-limit.js' */
|
|
15
15
|
|
|
16
16
|
const {
|
|
17
17
|
HTTP2_HEADER_RETRY_AFTER
|
|
@@ -26,6 +26,23 @@ const { HTTP_STATUS_TOO_MANY_REQUESTS } = http2.constants
|
|
|
26
26
|
* @param {Metadata} meta
|
|
27
27
|
*/
|
|
28
28
|
export function sendTooManyRequests(stream, limitInfo, policies, meta) {
|
|
29
|
+
_sendTooManyRequests(stream, {
|
|
30
|
+
limitInfo,
|
|
31
|
+
policies
|
|
32
|
+
}, meta)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {ServerHttp2Stream} stream
|
|
37
|
+
* @param {Pick<SendInfo, 'limitInfo' | 'policies'>} info
|
|
38
|
+
* @param {Metadata} meta
|
|
39
|
+
*/
|
|
40
|
+
export function _sendTooManyRequests(stream, info, meta) {
|
|
41
|
+
const {
|
|
42
|
+
limitInfo,
|
|
43
|
+
policies
|
|
44
|
+
} = info
|
|
45
|
+
|
|
29
46
|
send(stream, HTTP_STATUS_TOO_MANY_REQUESTS, {
|
|
30
47
|
[HTTP2_HEADER_RETRY_AFTER]: `${limitInfo.resetSeconds}`,
|
|
31
48
|
[HTTP_HEADER_RATE_LIMIT]: RateLimit.from(limitInfo),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { Challenge } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { Challenge } from '../../headers/www-authenticate.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
8
|
-
/** @import { ChallengeItem } from '
|
|
7
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
8
|
+
/** @import { ChallengeItem } from '../../headers/www-authenticate.js' */
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
11
|
HTTP2_HEADER_WWW_AUTHENTICATE
|
|
@@ -20,6 +20,6 @@ const { HTTP_STATUS_UNAUTHORIZED } = http2.constants
|
|
|
20
20
|
*/
|
|
21
21
|
export function sendUnauthorized(stream, challenge, meta) {
|
|
22
22
|
send(stream, HTTP_STATUS_UNAUTHORIZED, {
|
|
23
|
-
[HTTP2_HEADER_WWW_AUTHENTICATE]: challenge?.map(Challenge.encode),
|
|
23
|
+
[HTTP2_HEADER_WWW_AUTHENTICATE]: challenge?.map(Challenge.encode), // todo stringify ?
|
|
24
24
|
}, [ HTTP2_HEADER_WWW_AUTHENTICATE ], undefined, undefined, meta)
|
|
25
25
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { send } from '
|
|
3
|
+
import { send } from '../send-util.js'
|
|
4
4
|
|
|
5
5
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
6
|
-
/** @import { Metadata } from '
|
|
6
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
7
7
|
|
|
8
8
|
const { HTTP_STATUS_UNPROCESSABLE_ENTITY } = http2.constants
|
|
9
9
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { HTTP_HEADER_ACCEPT_PATCH, HTTP_HEADER_ACCEPT_POST, HTTP_HEADER_ACCEPT_QUERY } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { HTTP_HEADER_ACCEPT_PATCH, HTTP_HEADER_ACCEPT_POST, HTTP_HEADER_ACCEPT_QUERY } from '../../defs.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
7
|
+
/** @import { SendInfo, Metadata } from '../../defs.js' */
|
|
8
8
|
|
|
9
9
|
const { HTTP2_METHOD_POST, HTTP2_METHOD_PATCH } = http2.constants
|
|
10
10
|
|
|
@@ -17,11 +17,28 @@ const { HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE } = http2.constants
|
|
|
17
17
|
* @param {Metadata} meta
|
|
18
18
|
*/
|
|
19
19
|
export function sendUnsupportedMediaType(stream, acceptableMediaType, supportedQueryTypes, meta) {
|
|
20
|
+
_sendUnsupportedMediaType(stream, {
|
|
21
|
+
acceptableMediaType,
|
|
22
|
+
supportedQueryTypes
|
|
23
|
+
}, meta)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {ServerHttp2Stream} stream
|
|
28
|
+
* @param {Pick<SendInfo, 'acceptableMediaType' | 'supportedQueryTypes'>} info
|
|
29
|
+
* @param {Metadata} meta
|
|
30
|
+
*/
|
|
31
|
+
export function _sendUnsupportedMediaType(stream, info, meta) {
|
|
32
|
+
const {
|
|
33
|
+
supportedQueryTypes,
|
|
34
|
+
acceptableMediaType
|
|
35
|
+
} = info
|
|
36
|
+
|
|
20
37
|
const supportsQuery = supportedQueryTypes !== undefined && supportedQueryTypes.length > 0
|
|
21
38
|
const exposedHeaders = supportsQuery ? [ HTTP_HEADER_ACCEPT_QUERY, HTTP_HEADER_ACCEPT_POST ] : [ HTTP_HEADER_ACCEPT_POST ]
|
|
22
39
|
|
|
23
40
|
const method = HTTP2_METHOD_POST // todo pass in as parameter or split acceptable to post and patch types
|
|
24
|
-
const acceptable = Array.isArray(acceptableMediaType) ? acceptableMediaType : [ acceptableMediaType ]
|
|
41
|
+
const acceptable = Array.isArray(acceptableMediaType) ? acceptableMediaType : [ acceptableMediaType ] // todo undefined creates array of one item
|
|
25
42
|
const acceptHeader = (method === HTTP2_METHOD_POST) ? HTTP_HEADER_ACCEPT_POST : HTTP_HEADER_ACCEPT_PATCH
|
|
26
43
|
const acceptValue = ((method === HTTP2_METHOD_POST) || (method === HTTP2_METHOD_PATCH)) ? acceptable.join(',') : undefined
|
|
27
44
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { CONTENT_TYPE_TEXT } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
7
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
8
8
|
|
|
9
9
|
const { HTTP_STATUS_INTERNAL_SERVER_ERROR } = http2.constants
|
|
10
10
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { send } from '
|
|
3
|
+
import { send } from '../send-util.js'
|
|
4
4
|
|
|
5
5
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
6
|
-
/** @import { Metadata } from '
|
|
6
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
7
7
|
|
|
8
8
|
const { HTTP_STATUS_INSUFFICIENT_STORAGE } = http2.constants
|
|
9
9
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { CONTENT_TYPE_TEXT } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
7
|
+
/** @import { Metadata } from '../../defs.js' */
|
|
8
8
|
|
|
9
9
|
const { HTTP_STATUS_NOT_IMPLEMENTED } = http2.constants
|
|
10
10
|
|
|
@@ -15,4 +15,4 @@ const { HTTP_STATUS_NOT_IMPLEMENTED } = http2.constants
|
|
|
15
15
|
*/
|
|
16
16
|
export function sendNotImplemented(stream, message, meta) {
|
|
17
17
|
send(stream, HTTP_STATUS_NOT_IMPLEMENTED, {}, [], CONTENT_TYPE_TEXT, message, meta)
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import { CONTENT_TYPE_TEXT } from '
|
|
4
|
-
import { send } from '
|
|
3
|
+
import { CONTENT_TYPE_TEXT } from '../../headers/content-type.js'
|
|
4
|
+
import { send } from '../send-util.js'
|
|
5
5
|
|
|
6
6
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
7
|
-
/** @import { Metadata } from '
|
|
7
|
+
/** @import { SendInfo, Metadata } from '../../defs.js' */
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
HTTP2_HEADER_RETRY_AFTER
|
|
@@ -19,7 +19,19 @@ const { HTTP_STATUS_SERVICE_UNAVAILABLE } = http2.constants
|
|
|
19
19
|
* @param {Metadata} meta
|
|
20
20
|
*/
|
|
21
21
|
export function sendUnavailable(stream, message, retryAfter, meta) {
|
|
22
|
+
_sendUnavailable(stream, message, { retryAfter }, meta)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {ServerHttp2Stream} stream
|
|
27
|
+
* @param {string|undefined} message
|
|
28
|
+
* @param {Pick<SendInfo, 'retryAfter'>} info
|
|
29
|
+
* @param {Metadata} meta
|
|
30
|
+
*/
|
|
31
|
+
export function _sendUnavailable(stream, message, info, meta) {
|
|
32
|
+
const { retryAfter } = info
|
|
33
|
+
|
|
22
34
|
send(stream, HTTP_STATUS_SERVICE_UNAVAILABLE, {
|
|
23
35
|
[HTTP2_HEADER_RETRY_AFTER]: Number.isInteger(retryAfter) ? `${retryAfter}` : undefined
|
|
24
36
|
}, [ HTTP2_HEADER_RETRY_AFTER ], CONTENT_TYPE_TEXT, message, meta)
|
|
25
|
-
}
|
|
37
|
+
}
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
HTTP_HEADER_SERVER_TIMING,
|
|
5
5
|
HTTP_HEADER_TIMING_ALLOW_ORIGIN,
|
|
6
6
|
ServerTiming
|
|
7
|
-
} from '../server-timing.js'
|
|
7
|
+
} from '../headers/server-timing.js'
|
|
8
8
|
|
|
9
9
|
/** @import { OutgoingHttpHeaders } from 'node:http2' */
|
|
10
|
-
/** @import { Metadata } from '
|
|
10
|
+
/** @import { Metadata } from '../defs.js' */
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
13
|
HTTP2_HEADER_STATUS,
|
package/src/response/index.js
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
/** biome-ignore-all lint/performance/noBarrelFile: entry point */
|
|
2
2
|
/** biome-ignore-all lint/performance/noReExportAll: entry point */
|
|
3
|
-
export * from '
|
|
3
|
+
export * from '../defs.js'
|
|
4
|
+
export * from './header-util.js'
|
|
4
5
|
export * from './send-util.js'
|
|
5
6
|
// end common headers
|
|
6
7
|
|
|
7
|
-
export * from './accepted.js'
|
|
8
|
-
export * from './bytes.js'
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
20
|
-
export * from './
|
|
21
|
-
export * from './
|
|
22
|
-
export * from './
|
|
23
|
-
export * from './
|
|
24
|
-
export * from './
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './
|
|
28
|
-
export * from './
|
|
29
|
-
export * from './
|
|
30
|
-
export * from './
|
|
31
|
-
export * from './
|
|
32
|
-
export * from './
|
|
33
|
-
export * from './
|
|
34
|
-
export * from './
|
|
35
|
-
export * from './
|
|
36
|
-
export * from './
|
|
37
|
-
export * from './unauthorized.js'
|
|
38
|
-
export * from './
|
|
39
|
-
export * from './
|
|
40
|
-
export * from './
|
|
8
|
+
export * from './2xx/accepted.js'
|
|
9
|
+
export * from './2xx/bytes.js'
|
|
10
|
+
export * from './2xx/created.js'
|
|
11
|
+
export * from './2xx/json.js'
|
|
12
|
+
export * from './2xx/no-content.js'
|
|
13
|
+
export * from './2xx/partial-content.js'
|
|
14
|
+
export * from './2xx/preflight.js'
|
|
15
|
+
export * from './2xx/sse.js'
|
|
16
|
+
export * from './2xx/trace.js'
|
|
17
|
+
export * from './3xx/found.js'
|
|
18
|
+
export * from './3xx/moved-permanently.js'
|
|
19
|
+
export * from './3xx/multiple-choices.js'
|
|
20
|
+
export * from './3xx/not-modified.js'
|
|
21
|
+
export * from './3xx/permanent-redirect.js'
|
|
22
|
+
export * from './3xx/see-other.js'
|
|
23
|
+
export * from './3xx/temporary-redirect.js'
|
|
24
|
+
export * from './4xx/bad-request.js'
|
|
25
|
+
export * from './4xx/conflict.js'
|
|
26
|
+
export * from './4xx/content-too-large.js'
|
|
27
|
+
export * from './4xx/forbidden.js'
|
|
28
|
+
export * from './4xx/gone.js'
|
|
29
|
+
export * from './4xx/im-a-teapot.js'
|
|
30
|
+
export * from './4xx/not-acceptable.js'
|
|
31
|
+
export * from './4xx/not-allowed.js'
|
|
32
|
+
export * from './4xx/not-found.js'
|
|
33
|
+
export * from './4xx/payment-required.js'
|
|
34
|
+
export * from './4xx/precondition-failed.js'
|
|
35
|
+
export * from './4xx/range-not-satisfiable.js'
|
|
36
|
+
export * from './4xx/timeout.js'
|
|
37
|
+
export * from './4xx/too-many-requests.js'
|
|
38
|
+
export * from './4xx/unauthorized.js'
|
|
39
|
+
export * from './4xx/unprocessable.js'
|
|
40
|
+
export * from './4xx/unsupported-media.js'
|
|
41
|
+
export * from './5xx/error.js'
|
|
42
|
+
export * from './5xx/insufficient-storage.js'
|
|
43
|
+
export * from './5xx/not-implemented.js'
|
|
44
|
+
export * from './5xx/unavailable.js'
|
package/src/response/response.js
CHANGED
|
@@ -1,46 +1,51 @@
|
|
|
1
|
-
import { sendAccepted } from './accepted.js'
|
|
2
|
-
import { sendBytes } from './bytes.js'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { sendUnauthorized } from './unauthorized.js'
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
1
|
+
import { sendAccepted } from './2xx/accepted.js'
|
|
2
|
+
import { sendBytes } from './2xx/bytes.js'
|
|
3
|
+
import { sendCreated } from './2xx/created.js'
|
|
4
|
+
import { sendJSON_Encoded } from './2xx/json.js'
|
|
5
|
+
import { sendNoContent } from './2xx/no-content.js'
|
|
6
|
+
import { sendPartialContent } from './2xx/partial-content.js'
|
|
7
|
+
import { sendPreflight } from './2xx/preflight.js'
|
|
8
|
+
import { sendSSE } from './2xx/sse.js'
|
|
9
|
+
import { sendTrace } from './2xx/trace.js'
|
|
10
|
+
import { sendFound } from './3xx/found.js'
|
|
11
|
+
import { sendMovedPermanently } from './3xx/moved-permanently.js'
|
|
12
|
+
import { sendMultipleChoices } from './3xx/multiple-choices.js'
|
|
13
|
+
import { sendNotModified } from './3xx/not-modified.js'
|
|
14
|
+
import { sendPermanentRedirect } from './3xx/permanent-redirect.js'
|
|
15
|
+
import { sendSeeOther } from './3xx/see-other.js'
|
|
16
|
+
import { sendTemporaryRedirect } from './3xx/temporary-redirect.js'
|
|
17
|
+
import { sendBadRequest } from './4xx/bad-request.js'
|
|
18
|
+
import { sendConflict } from './4xx/conflict.js'
|
|
19
|
+
import { sendContentTooLarge } from './4xx/content-too-large.js'
|
|
20
|
+
import { sendForbidden } from './4xx/forbidden.js'
|
|
21
|
+
import { sendGone } from './4xx/gone.js'
|
|
22
|
+
import { sendImATeapot } from './4xx/im-a-teapot.js'
|
|
23
|
+
import { sendNotAcceptable } from './4xx/not-acceptable.js'
|
|
24
|
+
import { sendNotAllowed } from './4xx/not-allowed.js'
|
|
25
|
+
import { sendNotFound } from './4xx/not-found.js'
|
|
26
|
+
import { sendPaymentRequired } from './4xx/payment-required.js'
|
|
27
|
+
import { sendPreconditionFailed } from './4xx/precondition-failed.js'
|
|
28
|
+
import { sendRangeNotSatisfiable } from './4xx/range-not-satisfiable.js'
|
|
29
|
+
import { sendTimeout } from './4xx/timeout.js'
|
|
30
|
+
import { sendTooManyRequests } from './4xx/too-many-requests.js'
|
|
31
|
+
import { sendUnauthorized } from './4xx/unauthorized.js'
|
|
32
|
+
import { sendUnprocessable } from './4xx/unprocessable.js'
|
|
33
|
+
import { sendUnsupportedMediaType } from './4xx/unsupported-media.js'
|
|
34
|
+
import { sendError } from './5xx/error.js'
|
|
35
|
+
import { sendInsufficientStorage } from './5xx/insufficient-storage.js'
|
|
36
|
+
import { sendNotImplemented } from './5xx/not-implemented.js'
|
|
37
|
+
import { sendUnavailable } from './5xx/unavailable.js'
|
|
35
38
|
|
|
36
39
|
export const Response = {
|
|
37
40
|
accepted: sendAccepted,
|
|
41
|
+
badRequest: sendBadRequest,
|
|
38
42
|
bytes: sendBytes,
|
|
39
43
|
conflict: sendConflict,
|
|
40
44
|
contentTooLarge: sendContentTooLarge,
|
|
41
45
|
created: sendCreated,
|
|
42
46
|
error: sendError,
|
|
43
47
|
forbidden: sendForbidden,
|
|
48
|
+
found: sendFound,
|
|
44
49
|
gone: sendGone,
|
|
45
50
|
imATeapot: sendImATeapot,
|
|
46
51
|
insufficientStorage: sendInsufficientStorage,
|
|
@@ -54,6 +59,7 @@ export const Response = {
|
|
|
54
59
|
notImplemented: sendNotImplemented,
|
|
55
60
|
notModified: sendNotModified,
|
|
56
61
|
partialContent: sendPartialContent,
|
|
62
|
+
paymentRequired: sendPaymentRequired,
|
|
57
63
|
permanentRedirect: sendPermanentRedirect,
|
|
58
64
|
preconditionFailed: sendPreconditionFailed,
|
|
59
65
|
preflight: sendPreflight,
|