got 15.0.4 → 15.0.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.
@@ -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 readonly _abortListenerDisposer?;
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)
@@ -701,6 +701,8 @@ export type PaginationOptions<ElementType, BodyType> = {
701
701
 
702
702
  It should return an object representing Got options pointing to the next page. The options are merged automatically with the previous request, therefore the options returned `pagination.paginate(...)` must reflect changes only. If there are no more pages, `false` should be returned.
703
703
 
704
+ When pagination navigates to a different origin, Got strips inherited sensitive headers such as `authorization`, `cookie`, and `proxy-authorization`. If you trust the next-page URL and want to forward a sensitive header, return it explicitly from `pagination.paginate(...)`.
705
+
704
706
  @example
705
707
  ```
706
708
  import got from 'got';
@@ -1006,7 +1006,8 @@ export default class Options {
1006
1006
  updated = new URLSearchParams(value);
1007
1007
  }
1008
1008
  else if (value instanceof URLSearchParams) {
1009
- updated = value;
1009
+ // Clone so the caller-owned object is not stored by reference.
1010
+ updated = new URLSearchParams(value);
1010
1011
  }
1011
1012
  else {
1012
1013
  validateSearchParameters(value);
@@ -1037,10 +1038,11 @@ export default class Options {
1037
1038
  }
1038
1039
  }
1039
1040
  else if (url) {
1040
- url.search = searchParameters.toString();
1041
+ // Overrides the query string in the URL.
1042
+ url.search = updated.toString();
1041
1043
  }
1042
1044
  else {
1043
- this.#internals.searchParams = searchParameters;
1045
+ this.#internals.searchParams = updated;
1044
1046
  }
1045
1047
  }
1046
1048
  get searchParameters() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "15.0.4",
3
+ "version": "15.0.6",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",