@nxtedition/nxt-undici 2.0.32 → 2.0.34
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
1
2
|
import { isDisturbed, retry as retryFn } from '../utils.js'
|
|
2
3
|
|
|
3
4
|
class Handler {
|
|
@@ -12,6 +13,12 @@ class Handler {
|
|
|
12
13
|
this.reason = null
|
|
13
14
|
this.aborted = false
|
|
14
15
|
|
|
16
|
+
this.statusCode = null
|
|
17
|
+
this.rawHeaders = null
|
|
18
|
+
this.resume = null
|
|
19
|
+
this.statusMessage = null
|
|
20
|
+
this.headers = null
|
|
21
|
+
|
|
15
22
|
this.handler.onConnect((reason) => {
|
|
16
23
|
this.aborted = true
|
|
17
24
|
if (this.abort) {
|
|
@@ -35,15 +42,30 @@ class Handler {
|
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
onHeaders(statusCode, rawHeaders, resume, statusMessage, headers) {
|
|
38
|
-
this.headersSent
|
|
39
|
-
|
|
45
|
+
assert(!this.headersSent)
|
|
46
|
+
|
|
47
|
+
this.statusCode = statusCode
|
|
48
|
+
this.rawHeaders = rawHeaders
|
|
49
|
+
this.resume = resume
|
|
50
|
+
this.statusMessage = statusMessage
|
|
51
|
+
this.headers = headers
|
|
52
|
+
|
|
53
|
+
return true
|
|
40
54
|
}
|
|
41
55
|
|
|
42
56
|
onData(chunk) {
|
|
57
|
+
if (!this.headersSent) {
|
|
58
|
+
this.sendHeaders()
|
|
59
|
+
}
|
|
60
|
+
|
|
43
61
|
return this.handler.onData(chunk)
|
|
44
62
|
}
|
|
45
63
|
|
|
46
64
|
onComplete(rawTrailers) {
|
|
65
|
+
if (!this.headersSent) {
|
|
66
|
+
this.sendHeaders()
|
|
67
|
+
}
|
|
68
|
+
|
|
47
69
|
return this.handler.onComplete(rawTrailers)
|
|
48
70
|
}
|
|
49
71
|
|
|
@@ -57,7 +79,7 @@ class Handler {
|
|
|
57
79
|
return this.handler.onError(err)
|
|
58
80
|
}
|
|
59
81
|
|
|
60
|
-
this.opts.logger?.debug('retrying response')
|
|
82
|
+
this.opts.logger?.debug({ retryCount: this.count }, 'retrying response')
|
|
61
83
|
|
|
62
84
|
retryPromise
|
|
63
85
|
.then(() => {
|
|
@@ -71,6 +93,25 @@ class Handler {
|
|
|
71
93
|
}
|
|
72
94
|
})
|
|
73
95
|
}
|
|
96
|
+
|
|
97
|
+
sendHeaders() {
|
|
98
|
+
assert(!this.headersSent)
|
|
99
|
+
|
|
100
|
+
this.headersSent = true
|
|
101
|
+
this.handler.onHeaders(
|
|
102
|
+
this.statusCode,
|
|
103
|
+
this.rawHeaders,
|
|
104
|
+
this.resume,
|
|
105
|
+
this.statusMessage,
|
|
106
|
+
this.headers,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
this.statusCode = null
|
|
110
|
+
this.rawHeaders = null
|
|
111
|
+
this.resume = null
|
|
112
|
+
this.statusMessage = null
|
|
113
|
+
this.headers = null
|
|
114
|
+
}
|
|
74
115
|
}
|
|
75
116
|
|
|
76
117
|
export default (dispatch) => (opts, handler) => {
|