@nxtedition/lib 15.0.5 → 15.0.7
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/undici/interceptor/abort.js +7 -7
- package/undici/interceptor/catch.js +6 -6
- package/undici/interceptor/content.js +8 -8
- package/undici/interceptor/log.js +8 -9
- package/undici/interceptor/proxy.js +6 -6
- package/undici/interceptor/redirect.js +6 -6
- package/undici/interceptor/response-body-dump.js +6 -6
- package/undici/interceptor/response-body-retry.js +14 -9
- package/undici/interceptor/response-retry.js +8 -8
- package/undici/interceptor/response-status-retry.js +8 -8
- package/undici/interceptor/signal.js +6 -6
package/package.json
CHANGED
|
@@ -9,18 +9,18 @@ class Handler {
|
|
|
9
9
|
|
|
10
10
|
onConnect(abort) {
|
|
11
11
|
this.abort = abort
|
|
12
|
-
this.handler.onConnect((reason) => {
|
|
12
|
+
this.handler.onConnect?.((reason) => {
|
|
13
13
|
this.reason = reason ?? new AbortError()
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
onBodySent(chunk) {
|
|
18
|
-
return this.handler.onBodySent(chunk)
|
|
18
|
+
return this.handler.onBodySent?.(chunk)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
22
22
|
if (this.reason == null) {
|
|
23
|
-
const ret = this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
23
|
+
const ret = this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
24
24
|
if (this.reason == null) {
|
|
25
25
|
return ret
|
|
26
26
|
}
|
|
@@ -31,7 +31,7 @@ class Handler {
|
|
|
31
31
|
|
|
32
32
|
onData(chunk) {
|
|
33
33
|
if (this.reason == null) {
|
|
34
|
-
const ret = this.handler.onData(chunk)
|
|
34
|
+
const ret = this.handler.onData?.(chunk)
|
|
35
35
|
if (this.reason == null) {
|
|
36
36
|
return ret
|
|
37
37
|
}
|
|
@@ -49,12 +49,12 @@ class Handler {
|
|
|
49
49
|
|
|
50
50
|
onComplete(rawTrailers) {
|
|
51
51
|
return this.reason == null
|
|
52
|
-
? this.handler.onComplete(rawTrailers)
|
|
53
|
-
: this.handler.onError(this.reason)
|
|
52
|
+
? this.handler.onComplete?.(rawTrailers)
|
|
53
|
+
: this.handler.onError?.(this.reason)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
onError(err) {
|
|
57
|
-
return this.handler.onError(err)
|
|
57
|
+
return this.handler.onError?.(err)
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -6,7 +6,7 @@ class Handler {
|
|
|
6
6
|
onConnect(abort) {
|
|
7
7
|
this.abort = abort
|
|
8
8
|
try {
|
|
9
|
-
return this.handler.onConnect(abort)
|
|
9
|
+
return this.handler.onConnect?.(abort)
|
|
10
10
|
} catch (err) {
|
|
11
11
|
this.abort(err)
|
|
12
12
|
}
|
|
@@ -14,7 +14,7 @@ class Handler {
|
|
|
14
14
|
|
|
15
15
|
onBodySent(chunk) {
|
|
16
16
|
try {
|
|
17
|
-
return this.handler.onBodySent(chunk)
|
|
17
|
+
return this.handler.onBodySent?.(chunk)
|
|
18
18
|
} catch (err) {
|
|
19
19
|
this.abort(err)
|
|
20
20
|
}
|
|
@@ -22,7 +22,7 @@ class Handler {
|
|
|
22
22
|
|
|
23
23
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
24
24
|
try {
|
|
25
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
25
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
26
26
|
} catch (err) {
|
|
27
27
|
this.abort(err)
|
|
28
28
|
return false
|
|
@@ -31,7 +31,7 @@ class Handler {
|
|
|
31
31
|
|
|
32
32
|
onData(chunk) {
|
|
33
33
|
try {
|
|
34
|
-
return this.handler.onData(chunk)
|
|
34
|
+
return this.handler.onData?.(chunk)
|
|
35
35
|
} catch (err) {
|
|
36
36
|
this.abort(err)
|
|
37
37
|
return false
|
|
@@ -40,7 +40,7 @@ class Handler {
|
|
|
40
40
|
|
|
41
41
|
onComplete(rawTrailers) {
|
|
42
42
|
try {
|
|
43
|
-
return this.handler.onComplete(rawTrailers)
|
|
43
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
44
44
|
} catch (err) {
|
|
45
45
|
this.abort(err)
|
|
46
46
|
return false
|
|
@@ -48,7 +48,7 @@ class Handler {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
onError(err) {
|
|
51
|
-
return this.handler.onError(err)
|
|
51
|
+
return this.handler.onError?.(err)
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -15,11 +15,11 @@ class Handler {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
onConnect(abort) {
|
|
18
|
-
return this.handler.onConnect(abort)
|
|
18
|
+
return this.handler.onConnect?.(abort)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
onBodySent(chunk) {
|
|
22
|
-
return this.handler.onBodySent(chunk)
|
|
22
|
+
return this.handler.onBodySent?.(chunk)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
@@ -28,19 +28,19 @@ class Handler {
|
|
|
28
28
|
|
|
29
29
|
this.hasher = this.md5 != null ? crypto.createHash('md5') : null
|
|
30
30
|
|
|
31
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
31
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
onData(chunk) {
|
|
35
35
|
this.pos += chunk.length
|
|
36
36
|
this.hasher?.update(chunk)
|
|
37
|
-
return this.handler.onData(chunk)
|
|
37
|
+
return this.handler.onData?.(chunk)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
onComplete(rawTrailers) {
|
|
41
41
|
const hash = this.hasher?.digest('base64')
|
|
42
42
|
if (this.md5 != null && hash !== this.md5) {
|
|
43
|
-
this.handler.onError(
|
|
43
|
+
this.handler.onError?.(
|
|
44
44
|
Object.assign(new Error('Request Content-Length mismatch'), {
|
|
45
45
|
expected: this.md5,
|
|
46
46
|
actual: hash,
|
|
@@ -48,18 +48,18 @@ class Handler {
|
|
|
48
48
|
)
|
|
49
49
|
}
|
|
50
50
|
if (this.length != null && this.pos !== Number(this.length)) {
|
|
51
|
-
return this.handler.onError(
|
|
51
|
+
return this.handler.onError?.(
|
|
52
52
|
Object.assign(new Error('Request Content-Length mismatch'), {
|
|
53
53
|
expected: Number(this.length),
|
|
54
54
|
actual: this.pos,
|
|
55
55
|
}),
|
|
56
56
|
)
|
|
57
57
|
}
|
|
58
|
-
return this.handler.onComplete(rawTrailers)
|
|
58
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
onError(err) {
|
|
62
|
-
this.handler.onError(err)
|
|
62
|
+
this.handler.onError?.(err)
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -4,25 +4,24 @@ const xuid = require('xuid')
|
|
|
4
4
|
class Handler {
|
|
5
5
|
constructor(opts, { handler }) {
|
|
6
6
|
this.handler = handler
|
|
7
|
-
this.opts = opts
|
|
7
|
+
this.opts = opts.id ? opts : { ...opts, id: xuid() }
|
|
8
8
|
this.abort = null
|
|
9
9
|
this.aborted = false
|
|
10
|
-
|
|
11
|
-
this.logger = opts.logger.child({ ureq: { id: xuid() } })
|
|
10
|
+
this.logger = opts.logger.child({ ureq: { id: opts.id } })
|
|
12
11
|
this.pos = 0
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
onConnect(abort) {
|
|
16
15
|
this.abort = abort
|
|
17
16
|
this.logger.debug({ ureq: this.opts }, 'upstream request started')
|
|
18
|
-
this.handler.onConnect((reason) => {
|
|
17
|
+
this.handler.onConnect?.((reason) => {
|
|
19
18
|
this.aborted = true
|
|
20
19
|
this.abort(reason)
|
|
21
20
|
})
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
onBodySent(chunk) {
|
|
25
|
-
return this.handler.onBodySent(chunk)
|
|
24
|
+
return this.handler.onBodySent?.(chunk)
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
@@ -30,17 +29,17 @@ class Handler {
|
|
|
30
29
|
{ ures: { statusCode, headers: parseHeaders(rawHeaders) } },
|
|
31
30
|
'upstream request response',
|
|
32
31
|
)
|
|
33
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
32
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
onData(chunk) {
|
|
37
36
|
this.pos += chunk.length
|
|
38
|
-
return this.handler.onData(chunk)
|
|
37
|
+
return this.handler.onData?.(chunk)
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
onComplete(rawTrailers) {
|
|
42
41
|
this.logger.debug({ bytesRead: this.pos }, 'upstream request completed')
|
|
43
|
-
return this.handler.onComplete(rawTrailers)
|
|
42
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
onError(err) {
|
|
@@ -49,7 +48,7 @@ class Handler {
|
|
|
49
48
|
} else {
|
|
50
49
|
this.logger.error({ bytesRead: this.pos, err }, 'upstream request failed')
|
|
51
50
|
}
|
|
52
|
-
return this.handler.onError(err)
|
|
51
|
+
return this.handler.onError?.(err)
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -26,18 +26,18 @@ class Handler {
|
|
|
26
26
|
|
|
27
27
|
onConnect(abort) {
|
|
28
28
|
this.abort = abort
|
|
29
|
-
this.handler.onConnect((reason) => {
|
|
29
|
+
this.handler.onConnect?.((reason) => {
|
|
30
30
|
this.aborted = true
|
|
31
31
|
this.abort(reason)
|
|
32
32
|
})
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
onBodySent(chunk) {
|
|
36
|
-
return this.handler.onBodySent(chunk)
|
|
36
|
+
return this.handler.onBodySent?.(chunk)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
40
|
-
return this.handler.onHeaders(
|
|
40
|
+
return this.handler.onHeaders?.(
|
|
41
41
|
statusCode,
|
|
42
42
|
reduceHeaders(
|
|
43
43
|
{
|
|
@@ -58,15 +58,15 @@ class Handler {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
onData(chunk) {
|
|
61
|
-
return this.handler.onData(chunk)
|
|
61
|
+
return this.handler.onData?.(chunk)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
onComplete(rawTrailers) {
|
|
65
|
-
return this.handler.onComplete(rawTrailers)
|
|
65
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
onError(err) {
|
|
69
|
-
return this.handler.onError(err)
|
|
69
|
+
return this.handler.onError?.(err)
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -16,7 +16,7 @@ class Handler {
|
|
|
16
16
|
this.count = 0
|
|
17
17
|
this.location = null
|
|
18
18
|
|
|
19
|
-
this.handler.onConnect((reason) => {
|
|
19
|
+
this.handler.onConnect?.((reason) => {
|
|
20
20
|
this.aborted = true
|
|
21
21
|
if (this.abort) {
|
|
22
22
|
this.abort(reason)
|
|
@@ -39,12 +39,12 @@ class Handler {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
onError(error) {
|
|
42
|
-
this.handler.onError(error)
|
|
42
|
+
this.handler.onError?.(error)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
onHeaders(statusCode, headers, resume, statusText) {
|
|
46
46
|
if (redirectableStatusCodes.indexOf(statusCode) === -1) {
|
|
47
|
-
return this.handler.onHeaders(statusCode, headers, resume, statusText)
|
|
47
|
+
return this.handler.onHeaders?.(statusCode, headers, resume, statusText)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if (isDisturbed(this.opts.body)) {
|
|
@@ -110,7 +110,7 @@ class Handler {
|
|
|
110
110
|
servers and browsers implementors, we ignore the body as there is no specified way to eventually parse it.
|
|
111
111
|
*/
|
|
112
112
|
} else {
|
|
113
|
-
return this.handler.onData(chunk)
|
|
113
|
+
return this.handler.onData?.(chunk)
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -129,13 +129,13 @@ class Handler {
|
|
|
129
129
|
|
|
130
130
|
this.dispatch(this.opts, this)
|
|
131
131
|
} else {
|
|
132
|
-
this.handler.onComplete(trailers)
|
|
132
|
+
this.handler.onComplete?.(trailers)
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
onBodySent(chunk) {
|
|
137
137
|
if (this.handler.onBodySent) {
|
|
138
|
-
this.handler.onBodySent(chunk)
|
|
138
|
+
this.handler.onBodySent?.(chunk)
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -8,15 +8,15 @@ class Handler {
|
|
|
8
8
|
|
|
9
9
|
onConnect(abort) {
|
|
10
10
|
this.abort = abort
|
|
11
|
-
return this.handler.onConnect(abort)
|
|
11
|
+
return this.handler.onConnect?.(abort)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
onBodySent(chunk) {
|
|
15
|
-
return this.handler.onBodySent(chunk)
|
|
15
|
+
return this.handler.onBodySent?.(chunk)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
19
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
19
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
onData(chunk) {
|
|
@@ -25,7 +25,7 @@ class Handler {
|
|
|
25
25
|
return true
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
this.handler.onComplete([])
|
|
28
|
+
this.handler.onComplete?.([])
|
|
29
29
|
this.handler = null
|
|
30
30
|
|
|
31
31
|
this.abort(new AbortError('dump'))
|
|
@@ -34,11 +34,11 @@ class Handler {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
onComplete(rawTrailers) {
|
|
37
|
-
return this.handler.onComplete([])
|
|
37
|
+
return this.handler.onComplete?.([])
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
onError(err) {
|
|
41
|
-
return this.handler?.onError(err)
|
|
41
|
+
return this.handler?.onError?.(err)
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -21,7 +21,7 @@ class Handler {
|
|
|
21
21
|
this.error = null
|
|
22
22
|
this.etag = null
|
|
23
23
|
|
|
24
|
-
this.handler.onConnect((reason) => {
|
|
24
|
+
this.handler.onConnect?.((reason) => {
|
|
25
25
|
this.aborted = true
|
|
26
26
|
if (this.abort) {
|
|
27
27
|
this.abort(reason)
|
|
@@ -40,7 +40,7 @@ class Handler {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
onBodySent(chunk) {
|
|
43
|
-
return this.handler.onBodySent(chunk)
|
|
43
|
+
return this.handler.onBodySent?.(chunk)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
@@ -77,7 +77,12 @@ class Handler {
|
|
|
77
77
|
if (statusCode === 206) {
|
|
78
78
|
const contentRange = parseContentRange(findHeader(rawHeaders, 'content-range'))
|
|
79
79
|
if (!contentRange) {
|
|
80
|
-
return this.handler.onHeaders(
|
|
80
|
+
return this.handler.onHeaders?.(
|
|
81
|
+
statusCode,
|
|
82
|
+
rawHeaders,
|
|
83
|
+
() => this.resume(),
|
|
84
|
+
statusMessage,
|
|
85
|
+
)
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
const { start, size, end = size } = contentRange
|
|
@@ -97,17 +102,17 @@ class Handler {
|
|
|
97
102
|
|
|
98
103
|
this.etag = etag
|
|
99
104
|
this.resume = resume
|
|
100
|
-
return this.handler.onHeaders(statusCode, rawHeaders, () => this.resume(), statusMessage)
|
|
105
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, () => this.resume(), statusMessage)
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
onData(chunk) {
|
|
104
109
|
this.pos += chunk.length
|
|
105
110
|
this.count = 0
|
|
106
|
-
return this.handler.onData(chunk)
|
|
111
|
+
return this.handler.onData?.(chunk)
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
onComplete(rawTrailers) {
|
|
110
|
-
return this.handler.onComplete(rawTrailers)
|
|
115
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
onError(err) {
|
|
@@ -117,12 +122,12 @@ class Handler {
|
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
if (!this.resume || this.aborted || !this.etag || isDisturbed(this.opts.body)) {
|
|
120
|
-
return this.handler.onError(err)
|
|
125
|
+
return this.handler.onError?.(err)
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
const retryAfter = retryAfterFn(err, this.count++, this.opts)
|
|
124
129
|
if (retryAfter == null) {
|
|
125
|
-
return this.handler.onError(err)
|
|
130
|
+
return this.handler.onError?.(err)
|
|
126
131
|
}
|
|
127
132
|
assert(Number.isFinite(retryAfter), 'invalid retry')
|
|
128
133
|
|
|
@@ -142,7 +147,7 @@ class Handler {
|
|
|
142
147
|
try {
|
|
143
148
|
this.dispatch(this.opts, this)
|
|
144
149
|
} catch (err) {
|
|
145
|
-
this.handler.onError(err)
|
|
150
|
+
this.handler.onError?.(err)
|
|
146
151
|
}
|
|
147
152
|
}, retryAfter)
|
|
148
153
|
}
|
|
@@ -13,7 +13,7 @@ class Handler {
|
|
|
13
13
|
this.count = 0
|
|
14
14
|
this.retryAfter = null
|
|
15
15
|
|
|
16
|
-
this.handler.onConnect((reason) => {
|
|
16
|
+
this.handler.onConnect?.((reason) => {
|
|
17
17
|
this.aborted = true
|
|
18
18
|
if (this.abort) {
|
|
19
19
|
this.abort(reason)
|
|
@@ -32,20 +32,20 @@ class Handler {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
onBodySent(chunk) {
|
|
35
|
-
return this.handler.onBodySent(chunk)
|
|
35
|
+
return this.handler.onBodySent?.(chunk)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
39
39
|
this.aborted = true
|
|
40
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
40
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
onData(chunk) {
|
|
44
|
-
return this.handler.onData(chunk)
|
|
44
|
+
return this.handler.onData?.(chunk)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
onComplete(rawTrailers) {
|
|
48
|
-
return this.handler.onComplete(rawTrailers)
|
|
48
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
onError(err) {
|
|
@@ -55,12 +55,12 @@ class Handler {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (this.aborted || isDisturbed(this.opts.body)) {
|
|
58
|
-
return this.handler.onError(err)
|
|
58
|
+
return this.handler.onError?.(err)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const retryAfter = retryAfterFn(err, this.count++, this.opts)
|
|
62
62
|
if (retryAfter == null) {
|
|
63
|
-
return this.handler.onError(err)
|
|
63
|
+
return this.handler.onError?.(err)
|
|
64
64
|
}
|
|
65
65
|
assert(Number.isFinite(retryAfter), 'invalid retryAfter')
|
|
66
66
|
|
|
@@ -71,7 +71,7 @@ class Handler {
|
|
|
71
71
|
try {
|
|
72
72
|
this.dispatch(this.opts, this)
|
|
73
73
|
} catch (err2) {
|
|
74
|
-
this.handler.onError(err)
|
|
74
|
+
this.handler.onError?.(err)
|
|
75
75
|
}
|
|
76
76
|
}, retryAfter)
|
|
77
77
|
this.retryAfter = null
|
|
@@ -16,7 +16,7 @@ class Handler {
|
|
|
16
16
|
this.count = 0
|
|
17
17
|
this.retryAfter = null
|
|
18
18
|
|
|
19
|
-
this.handler.onConnect((reason) => {
|
|
19
|
+
this.handler.onConnect?.((reason) => {
|
|
20
20
|
this.aborted = true
|
|
21
21
|
if (this.abort) {
|
|
22
22
|
this.abort(reason)
|
|
@@ -35,19 +35,19 @@ class Handler {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
onBodySent(chunk) {
|
|
38
|
-
return this.handler.onBodySent(chunk)
|
|
38
|
+
return this.handler.onBodySent?.(chunk)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
42
42
|
if (statusCode < 400) {
|
|
43
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
43
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const err = createError(statusCode, { headers: parseHeaders(rawHeaders) })
|
|
47
47
|
|
|
48
48
|
const retryAfter = retryAfterFn(err, this.count++, this.opts)
|
|
49
49
|
if (retryAfter == null) {
|
|
50
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
50
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
51
51
|
}
|
|
52
52
|
assert(Number.isFinite(retryAfter), 'invalid retryAfter')
|
|
53
53
|
|
|
@@ -59,11 +59,11 @@ class Handler {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
onData(chunk) {
|
|
62
|
-
return this.handler.onData(chunk)
|
|
62
|
+
return this.handler.onData?.(chunk)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
onComplete(rawTrailers) {
|
|
66
|
-
return this.handler.onComplete(rawTrailers)
|
|
66
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
onError(err) {
|
|
@@ -73,7 +73,7 @@ class Handler {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
if (this.retryAfter == null || this.aborted || isDisturbed(this.opts.body)) {
|
|
76
|
-
return this.handler.onError(err)
|
|
76
|
+
return this.handler.onError?.(err)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
this.opts.logger?.debug('retrying response status', { retryAfter: this.retryAfter })
|
|
@@ -83,7 +83,7 @@ class Handler {
|
|
|
83
83
|
try {
|
|
84
84
|
this.dispatch(this.opts, this)
|
|
85
85
|
} catch (err) {
|
|
86
|
-
this.handler.onError(err)
|
|
86
|
+
this.handler.onError?.(err)
|
|
87
87
|
}
|
|
88
88
|
}, this.retryAfter)
|
|
89
89
|
this.retryAfter = null
|
|
@@ -14,30 +14,30 @@ class Handler {
|
|
|
14
14
|
if (this.signal.aborted) {
|
|
15
15
|
abort(this.signal.reason)
|
|
16
16
|
} else {
|
|
17
|
-
this.handler.onConnect(abort)
|
|
17
|
+
this.handler.onConnect?.(abort)
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
onBodySent(chunk) {
|
|
22
|
-
return this.handler.onBodySent(chunk)
|
|
22
|
+
return this.handler.onBodySent?.(chunk)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
26
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
26
|
+
return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
onData(chunk) {
|
|
30
|
-
return this.handler.onData(chunk)
|
|
30
|
+
return this.handler.onData?.(chunk)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
onComplete(rawTrailers) {
|
|
34
34
|
this.signal.removeEventListener('abort', this.abort)
|
|
35
|
-
return this.handler.onComplete(rawTrailers)
|
|
35
|
+
return this.handler.onComplete?.(rawTrailers)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
onError(err) {
|
|
39
39
|
this.signal.removeEventListener('abort', this.abort)
|
|
40
|
-
return this.handler.onError(err)
|
|
40
|
+
return this.handler.onError?.(err)
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|