@johntalton/http-util 7.0.1 → 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.
- package/package.json +1 -1
- package/src/body.js +11 -6
- package/src/defs.js +13 -4
- package/src/headers/accept-encoding.js +28 -5
- package/src/headers/accept-language.js +29 -5
- package/src/headers/accept.js +77 -32
- package/src/headers/cache-control.js +6 -3
- package/src/headers/client-hints.js +4 -3
- package/src/headers/conditional.js +17 -17
- package/src/headers/content-type.js +1 -1
- package/src/headers/link.js +8 -3
- package/src/headers/multipart.js +14 -6
- package/src/headers/range.js +2 -2
- package/src/headers/rate-limit.js +19 -3
- package/src/headers/server-timing.js +5 -3
- package/src/headers/util/kvp.js +2 -1
- package/src/headers/util/mime.js +16 -0
- package/src/headers/util/quote.js +1 -1
- package/src/headers/www-authenticate.js +35 -10
- package/src/response/2xx/accepted.js +2 -2
- package/src/response/2xx/created.js +3 -3
- package/src/response/2xx/no-content.js +3 -3
- package/src/response/2xx/preflight.js +9 -9
- package/src/response/3xx/found.js +3 -3
- package/src/response/3xx/moved-permanently.js +3 -3
- package/src/response/3xx/multiple-choices.js +3 -3
- package/src/response/3xx/not-modified.js +12 -5
- package/src/response/3xx/permanent-redirect.js +3 -3
- package/src/response/3xx/see-other.js +3 -3
- package/src/response/3xx/temporary-redirect.js +3 -3
- package/src/response/4xx/bad-request.js +1 -2
- package/src/response/4xx/conflict.js +2 -2
- package/src/response/4xx/content-too-large.js +2 -2
- package/src/response/4xx/forbidden.js +3 -3
- package/src/response/4xx/gone.js +2 -2
- package/src/response/4xx/im-a-teapot.js +2 -2
- package/src/response/4xx/not-allowed.js +5 -4
- package/src/response/4xx/payment-required.js +3 -3
- package/src/response/4xx/precondition-failed.js +3 -3
- package/src/response/4xx/range-not-satisfiable.js +3 -3
- package/src/response/4xx/timeout.js +3 -3
- package/src/response/4xx/too-many-requests.js +2 -5
- package/src/response/4xx/unauthorized.js +4 -4
- package/src/response/4xx/unprocessable.js +2 -2
- package/src/response/4xx/unsupported-media.js +15 -9
- package/src/response/header-util.js +8 -4
- package/src/response/send-util.js +77 -24
|
@@ -20,12 +20,13 @@ export const SERVER_TIMING_SEPARATOR = {
|
|
|
20
20
|
export class ServerTiming {
|
|
21
21
|
/**
|
|
22
22
|
* @param {Array<TimingsInfo>|undefined} timings
|
|
23
|
+
* @param {boolean} [asArray = false]
|
|
23
24
|
*/
|
|
24
|
-
static encode(timings) {
|
|
25
|
+
static encode(timings, asArray = false) {
|
|
25
26
|
if(timings === undefined) { return undefined }
|
|
26
27
|
if(timings.length <= 0) { return undefined }
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
const ary = timings
|
|
29
30
|
.map(({ name, duration, description }) => [
|
|
30
31
|
`${name}`,
|
|
31
32
|
description === undefined ? undefined : `${SERVER_TIMING_KEY_DESCRIPTION}${SERVER_TIMING_SEPARATOR.KVP}"${description}"`,
|
|
@@ -33,6 +34,7 @@ export class ServerTiming {
|
|
|
33
34
|
]
|
|
34
35
|
.filter(item => item !== undefined)
|
|
35
36
|
.join(SERVER_TIMING_SEPARATOR.PARAMETER))
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
return asArray ? ary : ary.join(SERVER_TIMING_SEPARATOR.METRIC) // todo COMMON_LIST_HEADER_JOINER_COMMA
|
|
37
39
|
}
|
|
38
40
|
}
|
package/src/headers/util/kvp.js
CHANGED
|
@@ -5,7 +5,6 @@ export const DEFAULT_DELIMITER = ';'
|
|
|
5
5
|
export const KVP_DELIMITER = '='
|
|
6
6
|
export const KVP_EMPTY = ''
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
export class KVP {
|
|
10
9
|
/**
|
|
11
10
|
* @param {Array<string>|undefined} params
|
|
@@ -40,6 +39,7 @@ export class KVP {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
/**
|
|
42
|
+
* Parses Key Value pair parameter list with leading named item.
|
|
43
43
|
* @param {string|undefined} str
|
|
44
44
|
* @param {Array<string>|undefined} [acceptableKeys=undefined]
|
|
45
45
|
*/
|
|
@@ -58,6 +58,7 @@ export class KVP {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
+
* Parses Key Value pair parameter list (no special treatment for leading key)
|
|
61
62
|
* @param {string|undefined} str
|
|
62
63
|
* @param {Array<string>|undefined} [acceptableKeys=undefined]
|
|
63
64
|
*/
|
package/src/headers/util/mime.js
CHANGED
|
@@ -74,4 +74,20 @@ export class Mime {
|
|
|
74
74
|
subtype
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {MimeItem} first
|
|
80
|
+
* @param {MimeItem} second
|
|
81
|
+
* @returns {boolean}
|
|
82
|
+
*/
|
|
83
|
+
static matches(first, second) {
|
|
84
|
+
if(first === undefined) { return false }
|
|
85
|
+
if(second === undefined) { return false }
|
|
86
|
+
|
|
87
|
+
const matchType = first.type === second.type || first.type === MIME_ANY || second.type === MIME_ANY
|
|
88
|
+
if(!matchType) { return false }
|
|
89
|
+
|
|
90
|
+
const matchSubtype = first.subtype === second.subtype || first.subtype === MIME_ANY || second.subtype === MIME_ANY
|
|
91
|
+
return matchSubtype
|
|
92
|
+
}
|
|
77
93
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { COMMON_LIST_HEADER_JOINER_COMMA, COMMON_LIST_VALUE_JOINER_COMMA } from "../defs.js"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @typedef {Object} ChallengeItem
|
|
3
5
|
* @property {string} scheme
|
|
@@ -35,9 +37,11 @@ export class Challenge {
|
|
|
35
37
|
/**
|
|
36
38
|
* @param {string} realm
|
|
37
39
|
* @param {string} [charset='utf-8']
|
|
38
|
-
* @returns {ChallengeItem}
|
|
40
|
+
* @returns {ChallengeItem|undefined}
|
|
39
41
|
*/
|
|
40
42
|
static basic(realm, charset = 'utf-8') {
|
|
43
|
+
if(realm === undefined) { return undefined }
|
|
44
|
+
|
|
41
45
|
const parameters = new Map([ [ 'realm', realm ] ])
|
|
42
46
|
if(charset !== undefined) { parameters.set('charset', charset) }
|
|
43
47
|
|
|
@@ -52,10 +56,10 @@ export class Challenge {
|
|
|
52
56
|
* @param {string|undefined} [scope]
|
|
53
57
|
* @param {BearerErrorCode} [error]
|
|
54
58
|
* @param {string} [errorDescription]
|
|
55
|
-
* @param {string} [
|
|
59
|
+
* @param {string} [_errorUri]
|
|
56
60
|
* @returns {ChallengeItem}
|
|
57
61
|
*/
|
|
58
|
-
static bearer(realm, scope, error, errorDescription,
|
|
62
|
+
static bearer(realm, scope, error, errorDescription, _errorUri) {
|
|
59
63
|
const parameters = new Map()
|
|
60
64
|
if(realm !== undefined) { parameters.set('realm', realm) }
|
|
61
65
|
if(scope !== undefined) { parameters.set('scope', scope) }
|
|
@@ -69,11 +73,11 @@ export class Challenge {
|
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
|
-
* @param {string}
|
|
73
|
-
* @param {string} [
|
|
76
|
+
* @param {string} _algorithm
|
|
77
|
+
* @param {string} [_realm]
|
|
74
78
|
* @returns {ChallengeItem}
|
|
75
79
|
*/
|
|
76
|
-
static digest(
|
|
80
|
+
static digest(_algorithm, _realm) {
|
|
77
81
|
return {
|
|
78
82
|
scheme: 'Digest'
|
|
79
83
|
}
|
|
@@ -89,18 +93,39 @@ export class Challenge {
|
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
/**
|
|
92
|
-
* @param {ChallengeItem}
|
|
96
|
+
* @param {Array<ChallengeItem> | ChallengeItem | undefined} challenges
|
|
97
|
+
* @param {boolean} [asArray = false]
|
|
98
|
+
*/
|
|
99
|
+
static encode(challenges, asArray = false) {
|
|
100
|
+
if(!Array.isArray(challenges)) { return Challenge.#encode(challenges) }
|
|
101
|
+
|
|
102
|
+
const ary = challenges
|
|
103
|
+
.map(Challenge.#encode)
|
|
104
|
+
.filter(c => c !== undefined)
|
|
105
|
+
|
|
106
|
+
return asArray ? ary : ary.join(COMMON_LIST_HEADER_JOINER_COMMA)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {ChallengeItem | undefined} challenge
|
|
93
111
|
*/
|
|
94
|
-
static encode(challenge) {
|
|
112
|
+
static #encode(challenge) {
|
|
113
|
+
if(challenge === undefined) { return undefined }
|
|
114
|
+
if(challenge.scheme === undefined) { return undefined }
|
|
115
|
+
if(challenge.scheme === '') { return undefined }
|
|
116
|
+
|
|
95
117
|
const parameters = challenge.parameters?.entries().map(([ key, value ]) => {
|
|
96
118
|
if(value === undefined) { return key }
|
|
97
119
|
if(paramNeedQuotes(key)) { return `${key}="${value}"` }
|
|
98
120
|
return `${key}=${value}`
|
|
99
121
|
})
|
|
100
122
|
|
|
101
|
-
|
|
123
|
+
if(parameters === undefined) { return challenge.scheme }
|
|
124
|
+
const params = [ ...parameters ]
|
|
125
|
+
if(params.length === 0) { return challenge.scheme }
|
|
102
126
|
|
|
103
|
-
|
|
127
|
+
const paramsStr = params.join(COMMON_LIST_VALUE_JOINER_COMMA)
|
|
128
|
+
return [ challenge.scheme, paramsStr ].join(' ')
|
|
104
129
|
}
|
|
105
130
|
}
|
|
106
131
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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_ACCEPTED } = http2.constants
|
|
|
12
12
|
* @param {Metadata} meta
|
|
13
13
|
*/
|
|
14
14
|
export function sendAccepted(stream, meta) {
|
|
15
|
-
|
|
15
|
+
send_no_body(stream, HTTP_STATUS_ACCEPTED, {}, [], meta)
|
|
16
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
3
|
import { Conditional } from '../../headers/conditional.js'
|
|
4
|
-
import {
|
|
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' */
|
|
@@ -28,9 +28,9 @@ export function sendCreated(stream, location, content, meta) {
|
|
|
28
28
|
|
|
29
29
|
const loc = (location instanceof URL) ? location.href : location
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
send_no_body(stream, HTTP_STATUS_CREATED, {
|
|
32
32
|
[HTTP2_HEADER_LOCATION]: loc,
|
|
33
33
|
[HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
|
|
34
34
|
[HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified)
|
|
35
|
-
}, [ HTTP2_HEADER_LOCATION ],
|
|
35
|
+
}, [ HTTP2_HEADER_LOCATION ], meta)
|
|
36
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
3
|
import { Conditional } from '../../headers/conditional.js'
|
|
4
|
-
import {
|
|
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' */
|
|
@@ -24,8 +24,8 @@ export function sendNoContent(stream, content, meta) {
|
|
|
24
24
|
lastModified
|
|
25
25
|
} = content
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
send_no_body(stream, HTTP_STATUS_NO_CONTENT, {
|
|
28
28
|
[HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
|
|
29
29
|
[HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified)
|
|
30
|
-
}, [],
|
|
30
|
+
}, [], meta)
|
|
31
31
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
COMMON_LIST_VALUE_JOINER_COMMA,
|
|
5
|
+
// HTTP_HEADER_ACCEPT_PATCH,
|
|
6
|
+
// HTTP_HEADER_ACCEPT_POST,
|
|
6
7
|
HTTP_HEADER_ACCEPT_QUERY,
|
|
7
8
|
HTTP_METHOD_QUERY,
|
|
8
9
|
HTTP2_HEADER_ACCESS_CONTROL_MAX_AGE,
|
|
9
10
|
PREFLIGHT_AGE_SECONDS
|
|
10
|
-
|
|
11
11
|
} from '../../defs.js'
|
|
12
|
-
import {
|
|
12
|
+
import { send_no_body } from '../send-util.js'
|
|
13
13
|
|
|
14
14
|
/** @import { ServerHttp2Stream } from 'node:http2' */
|
|
15
15
|
/** @import { SendInfo, Metadata } from '../../defs.js' */
|
|
@@ -47,8 +47,8 @@ export function sendPreflight(stream, info, meta) {
|
|
|
47
47
|
// todo: if supportedMethods includes POST | PATCH
|
|
48
48
|
// include accept-post / accept-patch headers
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
[HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS]: supportedMethods.join(
|
|
50
|
+
send_no_body(stream, HTTP_STATUS_OK, {
|
|
51
|
+
[HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS]: supportedMethods.join(COMMON_LIST_VALUE_JOINER_COMMA),
|
|
52
52
|
[HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS]: [
|
|
53
53
|
HTTP2_HEADER_IF_MATCH,
|
|
54
54
|
HTTP2_HEADER_IF_NONE_MATCH,
|
|
@@ -56,12 +56,12 @@ export function sendPreflight(stream, info, meta) {
|
|
|
56
56
|
HTTP2_HEADER_CONTENT_TYPE, // overrides cors safe restriction (for json)
|
|
57
57
|
HTTP2_HEADER_RANGE, // todo cors safe override not needed
|
|
58
58
|
HTTP2_HEADER_IF_RANGE
|
|
59
|
-
].join(
|
|
59
|
+
].join(COMMON_LIST_VALUE_JOINER_COMMA),
|
|
60
60
|
[HTTP2_HEADER_ACCESS_CONTROL_MAX_AGE]: PREFLIGHT_AGE_SECONDS,
|
|
61
61
|
// [HTTP_HEADER_ACCEPT_POST]: ,
|
|
62
62
|
// [HTTP_HEADER_ACCEPT_PATCH]: ,
|
|
63
63
|
[HTTP2_HEADER_ACCEPT_RANGES]: acceptRanges,
|
|
64
|
-
[HTTP_HEADER_ACCEPT_QUERY]: supportedQueryTypes?.join(
|
|
64
|
+
[HTTP_HEADER_ACCEPT_QUERY]: supportedQueryTypes?.join(COMMON_LIST_VALUE_JOINER_COMMA) // todo should empty array return undef
|
|
65
65
|
// Access-Control-Allow-Credentials
|
|
66
|
-
}, exposedHeaders,
|
|
66
|
+
}, exposedHeaders, meta)
|
|
67
67
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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' */
|
|
@@ -19,7 +19,7 @@ const { HTTP_STATUS_FOUND } = http2.constants
|
|
|
19
19
|
export function sendFound(stream, location, meta) {
|
|
20
20
|
const loc = (location instanceof URL) ? location.href : location
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
send_no_body(stream, HTTP_STATUS_FOUND, {
|
|
23
23
|
[HTTP2_HEADER_LOCATION]: loc
|
|
24
|
-
}, [ HTTP2_HEADER_LOCATION ],
|
|
24
|
+
}, [ HTTP2_HEADER_LOCATION ], meta)
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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' */
|
|
@@ -19,7 +19,7 @@ const { HTTP_STATUS_MOVED_PERMANENTLY } = http2.constants
|
|
|
19
19
|
export function sendMovedPermanently(stream, location, meta) {
|
|
20
20
|
const loc = (location instanceof URL) ? location.href : location
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
send_no_body(stream, HTTP_STATUS_MOVED_PERMANENTLY, {
|
|
23
23
|
[HTTP2_HEADER_LOCATION]: loc
|
|
24
|
-
}, [HTTP2_HEADER_LOCATION],
|
|
24
|
+
}, [HTTP2_HEADER_LOCATION], meta)
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
-
|
|
15
|
+
send_no_body(stream, HTTP_STATUS_MULTIPLE_CHOICES, {
|
|
16
16
|
// Alternates:
|
|
17
17
|
// TCN: list
|
|
18
18
|
// Vary: negotiate
|
|
19
|
-
}, [],
|
|
19
|
+
}, [], meta)
|
|
20
20
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
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 {
|
|
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' */
|
|
@@ -12,7 +14,9 @@ const {
|
|
|
12
14
|
HTTP2_HEADER_ETAG,
|
|
13
15
|
HTTP2_HEADER_LAST_MODIFIED,
|
|
14
16
|
HTTP2_HEADER_VARY,
|
|
15
|
-
HTTP2_HEADER_CACHE_CONTROL
|
|
17
|
+
HTTP2_HEADER_CACHE_CONTROL,
|
|
18
|
+
HTTP2_HEADER_ACCEPT,
|
|
19
|
+
HTTP2_HEADER_ACCEPT_ENCODING
|
|
16
20
|
} = http2.constants
|
|
17
21
|
|
|
18
22
|
const { HTTP_STATUS_NOT_MODIFIED } = http2.constants
|
|
@@ -30,11 +34,14 @@ export function sendNotModified(stream, content, meta) {
|
|
|
30
34
|
cacheControl
|
|
31
35
|
} = content
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
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),
|
|
35
42
|
[HTTP2_HEADER_CACHE_CONTROL]: CacheControl.encode(cacheControl),
|
|
36
43
|
[HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
|
|
37
44
|
[HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified),
|
|
38
45
|
[HTTP2_HEADER_AGE]: Number.isInteger(age) ? `${age}` : undefined
|
|
39
|
-
}, [ HTTP2_HEADER_AGE ],
|
|
46
|
+
}, [ HTTP2_HEADER_AGE ], meta)
|
|
40
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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' */
|
|
@@ -19,7 +19,7 @@ const { HTTP_STATUS_PERMANENT_REDIRECT } = http2.constants
|
|
|
19
19
|
export function sendPermanentRedirect(stream, location, meta) {
|
|
20
20
|
const loc = (location instanceof URL) ? location.href : location
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
send_no_body(stream, HTTP_STATUS_PERMANENT_REDIRECT, {
|
|
23
23
|
[HTTP2_HEADER_LOCATION]: loc
|
|
24
|
-
}, [ HTTP2_HEADER_LOCATION ],
|
|
24
|
+
}, [ HTTP2_HEADER_LOCATION ], meta)
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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' */
|
|
@@ -19,7 +19,7 @@ const { HTTP_STATUS_SEE_OTHER } = http2.constants
|
|
|
19
19
|
export function sendSeeOther(stream, location, meta) {
|
|
20
20
|
const loc = (location instanceof URL) ? location.href : location
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
send_no_body(stream, HTTP_STATUS_SEE_OTHER, {
|
|
23
23
|
[HTTP2_HEADER_LOCATION]: loc
|
|
24
|
-
}, [HTTP2_HEADER_LOCATION],
|
|
24
|
+
}, [HTTP2_HEADER_LOCATION], meta)
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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' */
|
|
@@ -19,7 +19,7 @@ const { HTTP_STATUS_TEMPORARY_REDIRECT } = http2.constants
|
|
|
19
19
|
export function sendTemporaryRedirect(stream, location, meta) {
|
|
20
20
|
const loc = (location instanceof URL) ? location.href : location
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
send_no_body(stream, HTTP_STATUS_TEMPORARY_REDIRECT, {
|
|
23
23
|
[HTTP2_HEADER_LOCATION]: loc
|
|
24
|
-
}, [ HTTP2_HEADER_LOCATION ],
|
|
24
|
+
}, [ HTTP2_HEADER_LOCATION ], meta)
|
|
25
25
|
}
|
|
@@ -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 {
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
16
|
-
}, [],
|
|
15
|
+
send_no_body(stream, HTTP_STATUS_FORBIDDEN, {
|
|
16
|
+
}, [], meta)
|
|
17
17
|
}
|
package/src/response/4xx/gone.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
15
|
+
send_no_body(stream, HTTP_STATUS_TEAPOT, {}, [], meta)
|
|
16
16
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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' */
|
|
@@ -19,7 +20,7 @@ const { HTTP2_HEADER_ALLOW } = http2.constants
|
|
|
19
20
|
export function sendNotAllowed(stream, info, meta) {
|
|
20
21
|
const { supportedMethods } = info
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
[HTTP2_HEADER_ALLOW]: supportedMethods.join(
|
|
24
|
-
}, [ HTTP2_HEADER_ALLOW ],
|
|
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)
|
|
25
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
-
|
|
16
|
-
}, [ ],
|
|
15
|
+
send_no_body(stream, HTTP_STATUS_PAYMENT_REQUIRED, {
|
|
16
|
+
}, [ ], meta)
|
|
17
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
3
|
import { Conditional } from '../../headers/conditional.js'
|
|
4
|
-
import {
|
|
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' */
|
|
@@ -24,8 +24,8 @@ export function sendPreconditionFailed(stream, content, meta) {
|
|
|
24
24
|
lastModified
|
|
25
25
|
} = content
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
send_no_body(stream, HTTP_STATUS_PRECONDITION_FAILED, {
|
|
28
28
|
[HTTP2_HEADER_ETAG]: Conditional.encodeEtag(etag),
|
|
29
29
|
[HTTP2_HEADER_LAST_MODIFIED]: Conditional.encodeFixDate(lastModified)
|
|
30
|
-
}, [],
|
|
30
|
+
}, [], meta)
|
|
31
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 {
|
|
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' */
|
|
@@ -24,7 +24,7 @@ export function sendRangeNotSatisfiable(stream, content, meta) {
|
|
|
24
24
|
/** @type {ContentRangeDirective} */
|
|
25
25
|
const invalidRange = { size: rangeDirective.size, range: CONTENT_RANGE_UNKNOWN }
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
send_no_body(stream, HTTP_STATUS_RANGE_NOT_SATISFIABLE, {
|
|
28
28
|
[HTTP2_HEADER_CONTENT_RANGE]: ContentRange.encode(invalidRange)
|
|
29
|
-
}, [ HTTP2_HEADER_CONTENT_RANGE ],
|
|
29
|
+
}, [ HTTP2_HEADER_CONTENT_RANGE ], meta)
|
|
30
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http2 from 'node:http2'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
-
|
|
19
|
+
send_no_body(stream, HTTP_STATUS_REQUEST_TIMEOUT, {
|
|
20
20
|
[HTTP2_HEADER_CONNECTION]: 'close'
|
|
21
|
-
}, [],
|
|
21
|
+
}, [], meta)
|
|
22
22
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
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 {
|
|
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' */
|
|
@@ -29,7 +28,7 @@ export function sendTooManyRequests(stream, info, meta) {
|
|
|
29
28
|
policies
|
|
30
29
|
} = info
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
send_no_body(stream, HTTP_STATUS_TOO_MANY_REQUESTS, {
|
|
33
32
|
[HTTP2_HEADER_RETRY_AFTER]: `${limitInfo.resetSeconds}`,
|
|
34
33
|
[HTTP_HEADER_RATE_LIMIT]: RateLimit.from(limitInfo),
|
|
35
34
|
[HTTP_HEADER_RATE_LIMIT_POLICY]: RateLimitPolicy.from(...policies)
|
|
@@ -39,7 +38,5 @@ export function sendTooManyRequests(stream, info, meta) {
|
|
|
39
38
|
HTTP_HEADER_RATE_LIMIT,
|
|
40
39
|
HTTP_HEADER_RATE_LIMIT_POLICY
|
|
41
40
|
],
|
|
42
|
-
CONTENT_TYPE_TEXT,
|
|
43
|
-
`Retry After ${limitInfo.resetSeconds} Seconds`,
|
|
44
41
|
meta)
|
|
45
42
|
}
|