got 15.0.4 → 15.0.5
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/dist/source/core/index.d.ts +2 -1
- package/dist/source/core/index.js +28 -18
- package/package.json +1 -1
|
@@ -103,7 +103,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
|
|
|
103
103
|
private _triggerRead;
|
|
104
104
|
private readonly _jobs;
|
|
105
105
|
private _cancelTimeouts?;
|
|
106
|
-
private
|
|
106
|
+
private _abortListenerDisposer?;
|
|
107
107
|
private _flushed;
|
|
108
108
|
private _aborted;
|
|
109
109
|
private _expectedContentLength?;
|
|
@@ -123,6 +123,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
|
|
|
123
123
|
end?: boolean;
|
|
124
124
|
}): T;
|
|
125
125
|
unpipe<T extends NodeJS.WritableStream>(destination: T): this;
|
|
126
|
+
private _attachAbortListener;
|
|
126
127
|
private _shouldIncrementallyDecodeBody;
|
|
127
128
|
private _checkContentLengthMismatch;
|
|
128
129
|
private _finalizeBody;
|
|
@@ -218,24 +218,6 @@ export default class Request extends Duplex {
|
|
|
218
218
|
if (is.nodeStream(body)) {
|
|
219
219
|
body.once('error', this._onBodyError);
|
|
220
220
|
}
|
|
221
|
-
if (this.options.signal) {
|
|
222
|
-
const abort = () => {
|
|
223
|
-
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static#return_value
|
|
224
|
-
if (this.options.signal?.reason?.name === 'TimeoutError') {
|
|
225
|
-
this.destroy(new TimeoutError(this.options.signal.reason, this.timings, this));
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
this.destroy(new AbortError(this));
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
if (this.options.signal.aborted) {
|
|
232
|
-
abort();
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
const abortListenerDisposer = addAbortListener(this.options.signal, abort);
|
|
236
|
-
this._abortListenerDisposer = abortListenerDisposer;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
221
|
}
|
|
240
222
|
async flush() {
|
|
241
223
|
if (this._flushed) {
|
|
@@ -243,6 +225,10 @@ export default class Request extends Duplex {
|
|
|
243
225
|
}
|
|
244
226
|
this._flushed = true;
|
|
245
227
|
try {
|
|
228
|
+
this._attachAbortListener();
|
|
229
|
+
if (this.destroyed) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
246
232
|
await this._finalizeBody();
|
|
247
233
|
if (this.destroyed) {
|
|
248
234
|
return;
|
|
@@ -564,6 +550,30 @@ export default class Request extends Duplex {
|
|
|
564
550
|
super.unpipe(destination);
|
|
565
551
|
return this;
|
|
566
552
|
}
|
|
553
|
+
_attachAbortListener() {
|
|
554
|
+
if (this._abortListenerDisposer) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const { signal } = this.options;
|
|
558
|
+
if (!signal) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const abort = () => {
|
|
562
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static#return_value
|
|
563
|
+
if (signal.reason?.name === 'TimeoutError') {
|
|
564
|
+
this.destroy(new TimeoutError(signal.reason, this.timings, this));
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
this.destroy(new AbortError(this));
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
if (signal.aborted) {
|
|
571
|
+
abort();
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
this._abortListenerDisposer = addAbortListener(signal, abort);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
567
577
|
_shouldIncrementallyDecodeBody() {
|
|
568
578
|
const { responseType, encoding } = this.options;
|
|
569
579
|
return Boolean(this._noPipe)
|