@nxtedition/nxt-undici 2.0.48 → 2.0.50
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/index.js +9 -0
- package/lib/readable.js +14 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -157,6 +157,7 @@ export async function request(url, opts) {
|
|
|
157
157
|
{
|
|
158
158
|
resolve,
|
|
159
159
|
reject,
|
|
160
|
+
method,
|
|
160
161
|
logger: opts.logger,
|
|
161
162
|
signal: opts.signal,
|
|
162
163
|
/** @type {Function | null} */ abort: null,
|
|
@@ -203,6 +204,7 @@ export async function request(url, opts) {
|
|
|
203
204
|
resume,
|
|
204
205
|
abort: this.abort,
|
|
205
206
|
highWaterMark: this.highWaterMark,
|
|
207
|
+
method: this.method,
|
|
206
208
|
statusCode,
|
|
207
209
|
statusMessage,
|
|
208
210
|
contentType,
|
|
@@ -210,6 +212,13 @@ export async function request(url, opts) {
|
|
|
210
212
|
size: Number.isFinite(contentLength) ? contentLength : null,
|
|
211
213
|
})
|
|
212
214
|
|
|
215
|
+
if (this.signal) {
|
|
216
|
+
this.body.on('close', () => {
|
|
217
|
+
this.signal?.removeEventListener('abort', this.onAbort)
|
|
218
|
+
this.signal = null
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
213
222
|
this.resolve(this.body)
|
|
214
223
|
this.resolve = null
|
|
215
224
|
this.reject = null
|
package/lib/readable.js
CHANGED
|
@@ -19,6 +19,7 @@ const kStatusMessage = Symbol('kStatusMessage')
|
|
|
19
19
|
const kHeaders = Symbol('kHeaders')
|
|
20
20
|
const kSize = Symbol('kSize')
|
|
21
21
|
const kHandler = Symbol('kHandler')
|
|
22
|
+
const kMethod = Symbol('kMethod')
|
|
22
23
|
|
|
23
24
|
const noop = () => {}
|
|
24
25
|
|
|
@@ -27,7 +28,17 @@ let ABORT_ERROR
|
|
|
27
28
|
export class BodyReadable extends Readable {
|
|
28
29
|
constructor(
|
|
29
30
|
handler,
|
|
30
|
-
{
|
|
31
|
+
{
|
|
32
|
+
contentType = '',
|
|
33
|
+
method,
|
|
34
|
+
statusCode,
|
|
35
|
+
statusMessage,
|
|
36
|
+
headers,
|
|
37
|
+
size,
|
|
38
|
+
abort,
|
|
39
|
+
highWaterMark,
|
|
40
|
+
resume,
|
|
41
|
+
},
|
|
31
42
|
) {
|
|
32
43
|
super({
|
|
33
44
|
autoDestroy: true,
|
|
@@ -90,7 +101,7 @@ export class BodyReadable extends Readable {
|
|
|
90
101
|
this[kHandler].signal = null
|
|
91
102
|
}
|
|
92
103
|
|
|
93
|
-
if (
|
|
104
|
+
if (!this[kReading]) {
|
|
94
105
|
// Workaround for Node "bug". If the stream is destroyed in same
|
|
95
106
|
// tick as it is created, then a user who is waiting for a
|
|
96
107
|
// promise (i.e micro tick) for installing a 'error' listener will
|
|
@@ -199,7 +210,7 @@ export class BodyReadable extends Readable {
|
|
|
199
210
|
? Number(this.headers['content-length'])
|
|
200
211
|
: null
|
|
201
212
|
|
|
202
|
-
if (contentLength != null && contentLength >= limit) {
|
|
213
|
+
if (this[kMethod] !== 'HEAD' && contentLength != null && contentLength >= limit) {
|
|
203
214
|
this.on('error', () => {}).destroy()
|
|
204
215
|
return
|
|
205
216
|
}
|