@nxtedition/nxt-undici 7.3.5 → 7.3.6
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/lib/interceptor/log.js +20 -0
- package/package.json +1 -1
package/lib/interceptor/log.js
CHANGED
|
@@ -19,6 +19,9 @@ class Handler extends DecoratorHandler {
|
|
|
19
19
|
#statusCode
|
|
20
20
|
#headers
|
|
21
21
|
|
|
22
|
+
#globalIndex = -1
|
|
23
|
+
#globalArray = (globalThis.__undici_requests ??= [])
|
|
24
|
+
|
|
22
25
|
constructor(logOpts, opts, { handler }) {
|
|
23
26
|
super(handler)
|
|
24
27
|
|
|
@@ -31,6 +34,8 @@ class Handler extends DecoratorHandler {
|
|
|
31
34
|
|
|
32
35
|
this.#logger.debug('upstream request started')
|
|
33
36
|
this.#timing.created = this.#created + performance.timeOrigin
|
|
37
|
+
|
|
38
|
+
this.#globalIndex = this.#globalArray.push(this) - 1
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
onConnect(abort) {
|
|
@@ -110,6 +115,8 @@ class Handler extends DecoratorHandler {
|
|
|
110
115
|
this.#logger.debug(data, 'upstream request completed')
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
this.onDone()
|
|
119
|
+
|
|
113
120
|
super.onComplete()
|
|
114
121
|
}
|
|
115
122
|
|
|
@@ -137,8 +144,21 @@ class Handler extends DecoratorHandler {
|
|
|
137
144
|
this.#logger.error(data, 'upstream request failed')
|
|
138
145
|
}
|
|
139
146
|
|
|
147
|
+
this.onDone()
|
|
148
|
+
|
|
140
149
|
super.onError(err)
|
|
141
150
|
}
|
|
151
|
+
|
|
152
|
+
onDone() {
|
|
153
|
+
if (this.#globalIndex !== -1) {
|
|
154
|
+
const tmp = this.#globalArray.pop()
|
|
155
|
+
if (tmp !== this) {
|
|
156
|
+
this.#globalArray[this.#globalIndex] = tmp
|
|
157
|
+
tmp.#globalIndex = this.#globalIndex
|
|
158
|
+
}
|
|
159
|
+
this.#globalIndex = -1
|
|
160
|
+
}
|
|
161
|
+
}
|
|
142
162
|
}
|
|
143
163
|
|
|
144
164
|
export default (logOpts) => (dispatch) => (opts, handler) =>
|