got 12.5.1 → 12.5.3

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.
@@ -109,6 +109,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
109
109
  private _triggerRead;
110
110
  private _jobs;
111
111
  private _cancelTimeouts;
112
+ private readonly _removeListeners;
112
113
  private _nativeResponse?;
113
114
  private _flushed;
114
115
  private _aborted;
@@ -163,6 +163,12 @@ export default class Request extends Duplex {
163
163
  writable: true,
164
164
  value: void 0
165
165
  });
166
+ Object.defineProperty(this, "_removeListeners", {
167
+ enumerable: true,
168
+ configurable: true,
169
+ writable: true,
170
+ value: void 0
171
+ });
166
172
  Object.defineProperty(this, "_nativeResponse", {
167
173
  enumerable: true,
168
174
  configurable: true,
@@ -196,6 +202,7 @@ export default class Request extends Duplex {
196
202
  this._unproxyEvents = noop;
197
203
  this._triggerRead = false;
198
204
  this._cancelTimeouts = noop;
205
+ this._removeListeners = noop;
199
206
  this._jobs = [];
200
207
  this._flushed = false;
201
208
  this._requestInitialized = false;
@@ -234,12 +241,6 @@ export default class Request extends Duplex {
234
241
  };
235
242
  return;
236
243
  }
237
- if (this.options.signal?.aborted) {
238
- this.destroy(new AbortError(this));
239
- }
240
- this.options.signal?.addEventListener('abort', () => {
241
- this.destroy(new AbortError(this));
242
- });
243
244
  // Important! If you replace `body` in a handler with another stream, make sure it's readable first.
244
245
  // The below is run only once.
245
246
  const { body } = this.options;
@@ -256,6 +257,20 @@ export default class Request extends Duplex {
256
257
  }
257
258
  });
258
259
  }
260
+ if (this.options.signal) {
261
+ const abort = () => {
262
+ this.destroy(new AbortError(this));
263
+ };
264
+ if (this.options.signal.aborted) {
265
+ abort();
266
+ }
267
+ else {
268
+ this.options.signal.addEventListener('abort', abort);
269
+ this._removeListeners = () => {
270
+ this.options.signal.removeEventListener('abort', abort);
271
+ };
272
+ }
273
+ }
259
274
  }
260
275
  async flush() {
261
276
  if (this._flushed) {
@@ -452,6 +467,7 @@ export default class Request extends Duplex {
452
467
  // Prevent further retries
453
468
  this._stopRetry();
454
469
  this._cancelTimeouts();
470
+ this._removeListeners();
455
471
  if (this.options) {
456
472
  const { body } = this.options;
457
473
  if (is.nodeStream(body)) {
@@ -24,7 +24,7 @@ export declare class TimeoutError extends Error {
24
24
  export default function timedOut(request: ClientRequest, delays: Delays, options: TimedOutOptions): () => void;
25
25
  declare module 'http' {
26
26
  interface ClientRequest {
27
- [reentry]: boolean;
27
+ [reentry]?: boolean;
28
28
  }
29
29
  }
30
30
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "12.5.1",
3
+ "version": "12.5.3",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",