@sveltejs/kit 1.0.0-next.344 → 1.0.0-next.347

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.
@@ -1,10 +1,13 @@
1
1
  import http from 'node:http';
2
2
  import https from 'node:https';
3
3
  import zlib from 'node:zlib';
4
- import Stream, { PassThrough, pipeline } from 'node:stream';
5
- import { types, deprecate } from 'node:util';
4
+ import Stream, { PassThrough, pipeline as pipeline$1 } from 'node:stream';
5
+ import { Buffer as Buffer$1 } from 'node:buffer';
6
+ import { types, promisify, deprecate } from 'node:util';
6
7
  import { format } from 'node:url';
7
- import { isIP } from 'net';
8
+ import { isIP } from 'node:net';
9
+ import 'node:fs';
10
+ import 'node:path';
8
11
  import { webcrypto } from 'crypto';
9
12
 
10
13
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -64,7 +67,7 @@ function dataUriToBuffer(uri) {
64
67
  var ponyfill_es2018 = {exports: {}};
65
68
 
66
69
  /**
67
- * web-streams-polyfill v3.2.0
70
+ * web-streams-polyfill v3.2.1
68
71
  */
69
72
 
70
73
  (function (module, exports) {
@@ -3766,10 +3769,16 @@ var ponyfill_es2018 = {exports: {}};
3766
3769
  const byteLengthSizeFunction = (chunk) => {
3767
3770
  return chunk.byteLength;
3768
3771
  };
3769
- Object.defineProperty(byteLengthSizeFunction, 'name', {
3770
- value: 'size',
3771
- configurable: true
3772
- });
3772
+ try {
3773
+ Object.defineProperty(byteLengthSizeFunction, 'name', {
3774
+ value: 'size',
3775
+ configurable: true
3776
+ });
3777
+ }
3778
+ catch (_a) {
3779
+ // This property is non-configurable in older browsers, so ignore if this throws.
3780
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
3781
+ }
3773
3782
  /**
3774
3783
  * A queuing strategy that counts the number of bytes in each chunk.
3775
3784
  *
@@ -3828,10 +3837,16 @@ var ponyfill_es2018 = {exports: {}};
3828
3837
  const countSizeFunction = () => {
3829
3838
  return 1;
3830
3839
  };
3831
- Object.defineProperty(countSizeFunction, 'name', {
3832
- value: 'size',
3833
- configurable: true
3834
- });
3840
+ try {
3841
+ Object.defineProperty(countSizeFunction, 'name', {
3842
+ value: 'size',
3843
+ configurable: true
3844
+ });
3845
+ }
3846
+ catch (_a) {
3847
+ // This property is non-configurable in older browsers, so ignore if this throws.
3848
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
3849
+ }
3835
3850
  /**
3836
3851
  * A queuing strategy that counts the number of chunks.
3837
3852
  *
@@ -4319,16 +4334,14 @@ try {
4319
4334
 
4320
4335
  /*! fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
4321
4336
 
4322
- /** @typedef {import('buffer').Blob} NodeBlob} */
4323
-
4324
4337
  // 64 KiB (same size chrome slice theirs blob into Uint8array's)
4325
4338
  const POOL_SIZE = 65536;
4326
4339
 
4327
- /** @param {(Blob | NodeBlob | Uint8Array)[]} parts */
4328
- async function * toIterator (parts, clone = true) {
4340
+ /** @param {(Blob | Uint8Array)[]} parts */
4341
+ async function * toIterator (parts, clone) {
4329
4342
  for (const part of parts) {
4330
4343
  if ('stream' in part) {
4331
- yield * part.stream();
4344
+ yield * (/** @type {AsyncIterableIterator<Uint8Array>} */ (part.stream()));
4332
4345
  } else if (ArrayBuffer.isView(part)) {
4333
4346
  if (clone) {
4334
4347
  let position = part.byteOffset;
@@ -4342,17 +4355,16 @@ async function * toIterator (parts, clone = true) {
4342
4355
  } else {
4343
4356
  yield part;
4344
4357
  }
4358
+ /* c8 ignore next 10 */
4345
4359
  } else {
4346
- /* c8 ignore start */
4347
4360
  // For blobs that have arrayBuffer but no stream method (nodes buffer.Blob)
4348
- let position = 0;
4349
- while (position !== part.size) {
4350
- const chunk = part.slice(position, Math.min(part.size, position + POOL_SIZE));
4361
+ let position = 0, b = (/** @type {Blob} */ (part));
4362
+ while (position !== b.size) {
4363
+ const chunk = b.slice(position, Math.min(b.size, position + POOL_SIZE));
4351
4364
  const buffer = await chunk.arrayBuffer();
4352
4365
  position += buffer.byteLength;
4353
4366
  yield new Uint8Array(buffer);
4354
4367
  }
4355
- /* c8 ignore end */
4356
4368
  }
4357
4369
  }
4358
4370
  }
@@ -4362,6 +4374,7 @@ const _Blob = class Blob {
4362
4374
  #parts = []
4363
4375
  #type = ''
4364
4376
  #size = 0
4377
+ #endings = 'transparent'
4365
4378
 
4366
4379
  /**
4367
4380
  * The Blob() constructor returns a new Blob object. The content
@@ -4369,7 +4382,7 @@ const _Blob = class Blob {
4369
4382
  * in the parameter array.
4370
4383
  *
4371
4384
  * @param {*} blobParts
4372
- * @param {{ type?: string }} [options]
4385
+ * @param {{ type?: string, endings?: string }} [options]
4373
4386
  */
4374
4387
  constructor (blobParts = [], options = {}) {
4375
4388
  if (typeof blobParts !== 'object' || blobParts === null) {
@@ -4396,15 +4409,19 @@ const _Blob = class Blob {
4396
4409
  } else if (element instanceof Blob) {
4397
4410
  part = element;
4398
4411
  } else {
4399
- part = encoder.encode(element);
4412
+ part = encoder.encode(`${element}`);
4400
4413
  }
4401
4414
 
4402
- this.#size += ArrayBuffer.isView(part) ? part.byteLength : part.size;
4403
- this.#parts.push(part);
4415
+ const size = ArrayBuffer.isView(part) ? part.byteLength : part.size;
4416
+ // Avoid pushing empty parts into the array to better GC them
4417
+ if (size) {
4418
+ this.#size += size;
4419
+ this.#parts.push(part);
4420
+ }
4404
4421
  }
4405
4422
 
4423
+ this.#endings = `${options.endings === undefined ? 'transparent' : options.endings}`;
4406
4424
  const type = options.type === undefined ? '' : String(options.type);
4407
-
4408
4425
  this.#type = /^[\x20-\x7E]*$/.test(type) ? type : '';
4409
4426
  }
4410
4427
 
@@ -4470,6 +4487,7 @@ const _Blob = class Blob {
4470
4487
  const it = toIterator(this.#parts, true);
4471
4488
 
4472
4489
  return new globalThis.ReadableStream({
4490
+ // @ts-ignore
4473
4491
  type: 'bytes',
4474
4492
  async pull (ctrl) {
4475
4493
  const chunk = await it.next();
@@ -4601,6 +4619,11 @@ const _File = class File extends Blob$1 {
4601
4619
  get [Symbol.toStringTag] () {
4602
4620
  return 'File'
4603
4621
  }
4622
+
4623
+ static [Symbol.hasInstance] (object) {
4624
+ return !!object && object instanceof Blob$1 &&
4625
+ /^(File)$/.test(object[Symbol.toStringTag])
4626
+ }
4604
4627
  };
4605
4628
 
4606
4629
  /** @type {typeof globalThis.File} */// @ts-ignore
@@ -4743,6 +4766,22 @@ const isAbortSignal = object => {
4743
4766
  );
4744
4767
  };
4745
4768
 
4769
+ /**
4770
+ * isDomainOrSubdomain reports whether sub is a subdomain (or exact match) of
4771
+ * the parent domain.
4772
+ *
4773
+ * Both domains must already be in canonical form.
4774
+ * @param {string|URL} original
4775
+ * @param {string|URL} destination
4776
+ */
4777
+ const isDomainOrSubdomain = (destination, original) => {
4778
+ const orig = new URL(original).hostname;
4779
+ const dest = new URL(destination).hostname;
4780
+
4781
+ return orig === dest || orig.endsWith(`.${dest}`);
4782
+ };
4783
+
4784
+ const pipeline = promisify(Stream.pipeline);
4746
4785
  const INTERNALS$2 = Symbol('Body internals');
4747
4786
 
4748
4787
  /**
@@ -4765,13 +4804,13 @@ class Body {
4765
4804
  body = null;
4766
4805
  } else if (isURLSearchParameters(body)) {
4767
4806
  // Body is a URLSearchParams
4768
- body = Buffer.from(body.toString());
4769
- } else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (types.isAnyArrayBuffer(body)) {
4807
+ body = Buffer$1.from(body.toString());
4808
+ } else if (isBlob(body)) ; else if (Buffer$1.isBuffer(body)) ; else if (types.isAnyArrayBuffer(body)) {
4770
4809
  // Body is ArrayBuffer
4771
- body = Buffer.from(body);
4810
+ body = Buffer$1.from(body);
4772
4811
  } else if (ArrayBuffer.isView(body)) {
4773
4812
  // Body is ArrayBufferView
4774
- body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
4813
+ body = Buffer$1.from(body.buffer, body.byteOffset, body.byteLength);
4775
4814
  } else if (body instanceof Stream) ; else if (body instanceof FormData) {
4776
4815
  // Body is FormData
4777
4816
  body = formDataToBlob(body);
@@ -4779,12 +4818,12 @@ class Body {
4779
4818
  } else {
4780
4819
  // None of the above
4781
4820
  // coerce to string then buffer
4782
- body = Buffer.from(String(body));
4821
+ body = Buffer$1.from(String(body));
4783
4822
  }
4784
4823
 
4785
4824
  let stream = body;
4786
4825
 
4787
- if (Buffer.isBuffer(body)) {
4826
+ if (Buffer$1.isBuffer(body)) {
4788
4827
  stream = Stream.Readable.from(body);
4789
4828
  } else if (isBlob(body)) {
4790
4829
  stream = Stream.Readable.from(body.stream());
@@ -4852,7 +4891,7 @@ class Body {
4852
4891
  */
4853
4892
  async blob() {
4854
4893
  const ct = (this.headers && this.headers.get('content-type')) || (this[INTERNALS$2].body && this[INTERNALS$2].body.type) || '';
4855
- const buf = await this.buffer();
4894
+ const buf = await this.arrayBuffer();
4856
4895
 
4857
4896
  return new Blob$1([buf], {
4858
4897
  type: ct
@@ -4865,8 +4904,8 @@ class Body {
4865
4904
  * @return Promise
4866
4905
  */
4867
4906
  async json() {
4868
- const buffer = await consumeBody(this);
4869
- return JSON.parse(buffer.toString());
4907
+ const text = await this.text();
4908
+ return JSON.parse(text);
4870
4909
  }
4871
4910
 
4872
4911
  /**
@@ -4876,7 +4915,7 @@ class Body {
4876
4915
  */
4877
4916
  async text() {
4878
4917
  const buffer = await consumeBody(this);
4879
- return buffer.toString();
4918
+ return new TextDecoder().decode(buffer);
4880
4919
  }
4881
4920
 
4882
4921
  /**
@@ -4898,7 +4937,10 @@ Object.defineProperties(Body.prototype, {
4898
4937
  arrayBuffer: {enumerable: true},
4899
4938
  blob: {enumerable: true},
4900
4939
  json: {enumerable: true},
4901
- text: {enumerable: true}
4940
+ text: {enumerable: true},
4941
+ data: {get: deprecate(() => {},
4942
+ 'data doesn\'t exist, use json(), text(), arrayBuffer(), or body instead',
4943
+ 'https://github.com/node-fetch/node-fetch/issues/1000 (response)')}
4902
4944
  });
4903
4945
 
4904
4946
  /**
@@ -4923,12 +4965,12 @@ async function consumeBody(data) {
4923
4965
 
4924
4966
  // Body is null
4925
4967
  if (body === null) {
4926
- return Buffer.alloc(0);
4968
+ return Buffer$1.alloc(0);
4927
4969
  }
4928
4970
 
4929
4971
  /* c8 ignore next 3 */
4930
4972
  if (!(body instanceof Stream)) {
4931
- return Buffer.alloc(0);
4973
+ return Buffer$1.alloc(0);
4932
4974
  }
4933
4975
 
4934
4976
  // Body is stream
@@ -4955,10 +4997,10 @@ async function consumeBody(data) {
4955
4997
  if (body.readableEnded === true || body._readableState.ended === true) {
4956
4998
  try {
4957
4999
  if (accum.every(c => typeof c === 'string')) {
4958
- return Buffer.from(accum.join(''));
5000
+ return Buffer$1.from(accum.join(''));
4959
5001
  }
4960
5002
 
4961
- return Buffer.concat(accum, accumBytes);
5003
+ return Buffer$1.concat(accum, accumBytes);
4962
5004
  } catch (error) {
4963
5005
  throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, 'system', error);
4964
5006
  }
@@ -5038,7 +5080,7 @@ const extractContentType = (body, request) => {
5038
5080
  }
5039
5081
 
5040
5082
  // Body is a Buffer (Buffer, ArrayBuffer or ArrayBufferView)
5041
- if (Buffer.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
5083
+ if (Buffer$1.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
5042
5084
  return null;
5043
5085
  }
5044
5086
 
@@ -5083,7 +5125,7 @@ const getTotalBytes = request => {
5083
5125
  }
5084
5126
 
5085
5127
  // Body is Buffer
5086
- if (Buffer.isBuffer(body)) {
5128
+ if (Buffer$1.isBuffer(body)) {
5087
5129
  return body.length;
5088
5130
  }
5089
5131
 
@@ -5101,15 +5143,15 @@ const getTotalBytes = request => {
5101
5143
  *
5102
5144
  * @param {Stream.Writable} dest The stream to write to.
5103
5145
  * @param obj.body Body object from the Body instance.
5104
- * @returns {void}
5146
+ * @returns {Promise<void>}
5105
5147
  */
5106
- const writeToStream = (dest, {body}) => {
5148
+ const writeToStream = async (dest, {body}) => {
5107
5149
  if (body === null) {
5108
5150
  // Body is null
5109
5151
  dest.end();
5110
5152
  } else {
5111
5153
  // Body is stream
5112
- body.pipe(dest);
5154
+ await pipeline(body, dest);
5113
5155
  }
5114
5156
  };
5115
5157
 
@@ -5119,6 +5161,7 @@ const writeToStream = (dest, {body}) => {
5119
5161
  * Headers class offers convenient helpers
5120
5162
  */
5121
5163
 
5164
+ /* c8 ignore next 9 */
5122
5165
  const validateHeaderName = typeof http.validateHeaderName === 'function' ?
5123
5166
  http.validateHeaderName :
5124
5167
  name => {
@@ -5129,6 +5172,7 @@ const validateHeaderName = typeof http.validateHeaderName === 'function' ?
5129
5172
  }
5130
5173
  };
5131
5174
 
5175
+ /* c8 ignore next 9 */
5132
5176
  const validateHeaderValue = typeof http.validateHeaderValue === 'function' ?
5133
5177
  http.validateHeaderValue :
5134
5178
  (name, value) => {
@@ -5251,8 +5295,8 @@ class Headers extends URLSearchParams {
5251
5295
  return Reflect.get(target, p, receiver);
5252
5296
  }
5253
5297
  }
5254
- /* c8 ignore next */
5255
5298
  });
5299
+ /* c8 ignore next */
5256
5300
  }
5257
5301
 
5258
5302
  get [Symbol.toStringTag]() {
@@ -5873,12 +5917,20 @@ function parseReferrerPolicyFromHeader(headers) {
5873
5917
  return policy;
5874
5918
  }
5875
5919
 
5920
+ /**
5921
+ * Request.js
5922
+ *
5923
+ * Request class contains server only options
5924
+ *
5925
+ * All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
5926
+ */
5927
+
5876
5928
  const INTERNALS = Symbol('Request internals');
5877
5929
 
5878
5930
  /**
5879
5931
  * Check if `obj` is an instance of Request.
5880
5932
  *
5881
- * @param {*} obj
5933
+ * @param {*} object
5882
5934
  * @return {boolean}
5883
5935
  */
5884
5936
  const isRequest = object => {
@@ -5888,6 +5940,10 @@ const isRequest = object => {
5888
5940
  );
5889
5941
  };
5890
5942
 
5943
+ const doBadDataWarn = deprecate(() => {},
5944
+ '.data is not a valid RequestInit property, use .body instead',
5945
+ 'https://github.com/node-fetch/node-fetch/issues/1000 (request)');
5946
+
5891
5947
  /**
5892
5948
  * Request class
5893
5949
  *
@@ -5910,14 +5966,20 @@ class Request extends Body {
5910
5966
  }
5911
5967
 
5912
5968
  if (parsedURL.username !== '' || parsedURL.password !== '') {
5913
- throw new TypeError(`${parsedURL} is an url with embedded credentails.`);
5969
+ throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
5914
5970
  }
5915
5971
 
5916
5972
  let method = init.method || input.method || 'GET';
5917
- method = method.toUpperCase();
5973
+ if (/^(delete|get|head|options|post|put)$/i.test(method)) {
5974
+ method = method.toUpperCase();
5975
+ }
5976
+
5977
+ if ('data' in init) {
5978
+ doBadDataWarn();
5979
+ }
5918
5980
 
5919
5981
  // eslint-disable-next-line no-eq-null, eqeqeq
5920
- if (((init.body != null || isRequest(input)) && input.body !== null) &&
5982
+ if ((init.body != null || (isRequest(input) && input.body !== null)) &&
5921
5983
  (method === 'GET' || method === 'HEAD')) {
5922
5984
  throw new TypeError('Request with GET/HEAD method cannot have body');
5923
5985
  }
@@ -5990,14 +6052,17 @@ class Request extends Body {
5990
6052
  this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || '';
5991
6053
  }
5992
6054
 
6055
+ /** @returns {string} */
5993
6056
  get method() {
5994
6057
  return this[INTERNALS].method;
5995
6058
  }
5996
6059
 
6060
+ /** @returns {string} */
5997
6061
  get url() {
5998
6062
  return format(this[INTERNALS].parsedURL);
5999
6063
  }
6000
6064
 
6065
+ /** @returns {Headers} */
6001
6066
  get headers() {
6002
6067
  return this[INTERNALS].headers;
6003
6068
  }
@@ -6006,6 +6071,7 @@ class Request extends Body {
6006
6071
  return this[INTERNALS].redirect;
6007
6072
  }
6008
6073
 
6074
+ /** @returns {AbortSignal} */
6009
6075
  get signal() {
6010
6076
  return this[INTERNALS].signal;
6011
6077
  }
@@ -6063,8 +6129,8 @@ Object.defineProperties(Request.prototype, {
6063
6129
  /**
6064
6130
  * Convert a Request to Node.js http request options.
6065
6131
  *
6066
- * @param Request A Request instance
6067
- * @return Object The options object to be passed to http.request
6132
+ * @param {Request} request - A Request instance
6133
+ * @return The options object to be passed to http.request
6068
6134
  */
6069
6135
  const getNodeRequestOptions = request => {
6070
6136
  const {parsedURL} = request[INTERNALS];
@@ -6153,6 +6219,7 @@ const getNodeRequestOptions = request => {
6153
6219
  };
6154
6220
 
6155
6221
  return {
6222
+ /** @type {URL} */
6156
6223
  parsedURL,
6157
6224
  options
6158
6225
  };
@@ -6167,6 +6234,21 @@ class AbortError extends FetchBaseError {
6167
6234
  }
6168
6235
  }
6169
6236
 
6237
+ /*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
6238
+
6239
+ if (!globalThis.DOMException) {
6240
+ try {
6241
+ const { MessageChannel } = require('worker_threads'),
6242
+ port = new MessageChannel().port1,
6243
+ ab = new ArrayBuffer();
6244
+ port.postMessage(ab, [ab, ab]);
6245
+ } catch (err) {
6246
+ err.constructor.name === 'DOMException' && (
6247
+ globalThis.DOMException = err.constructor
6248
+ );
6249
+ }
6250
+ }
6251
+
6170
6252
  /**
6171
6253
  * Index.js
6172
6254
  *
@@ -6230,7 +6312,7 @@ async function fetch(url, options_) {
6230
6312
  };
6231
6313
 
6232
6314
  // Send request
6233
- const request_ = send(parsedURL, options);
6315
+ const request_ = send(parsedURL.toString(), options);
6234
6316
 
6235
6317
  if (signal) {
6236
6318
  signal.addEventListener('abort', abortAndFinalize);
@@ -6282,7 +6364,19 @@ async function fetch(url, options_) {
6282
6364
  const location = headers.get('Location');
6283
6365
 
6284
6366
  // HTTP fetch step 5.3
6285
- const locationURL = location === null ? null : new URL(location, request.url);
6367
+ let locationURL = null;
6368
+ try {
6369
+ locationURL = location === null ? null : new URL(location, request.url);
6370
+ } catch {
6371
+ // error here can only be invalid URL in Location: header
6372
+ // do not throw when options.redirect == manual
6373
+ // let the user extract the errorneous redirect URL
6374
+ if (request.redirect !== 'manual') {
6375
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
6376
+ finalize();
6377
+ return;
6378
+ }
6379
+ }
6286
6380
 
6287
6381
  // HTTP fetch step 5.5
6288
6382
  switch (request.redirect) {
@@ -6291,11 +6385,7 @@ async function fetch(url, options_) {
6291
6385
  finalize();
6292
6386
  return;
6293
6387
  case 'manual':
6294
- // Node-fetch-specific step: make manual redirect a bit easier to use by setting the Location header value to the resolved URL.
6295
- if (locationURL !== null) {
6296
- headers.set('Location', locationURL);
6297
- }
6298
-
6388
+ // Nothing to do
6299
6389
  break;
6300
6390
  case 'follow': {
6301
6391
  // HTTP-redirect fetch step 2
@@ -6326,6 +6416,18 @@ async function fetch(url, options_) {
6326
6416
  referrerPolicy: request.referrerPolicy
6327
6417
  };
6328
6418
 
6419
+ // when forwarding sensitive headers like "Authorization",
6420
+ // "WWW-Authenticate", and "Cookie" to untrusted targets,
6421
+ // headers will be ignored when following a redirect to a domain
6422
+ // that is not a subdomain match or exact match of the initial domain.
6423
+ // For example, a redirect from "foo.com" to either "foo.com" or "sub.foo.com"
6424
+ // will forward the sensitive headers, but a redirect to "bar.com" will not.
6425
+ if (!isDomainOrSubdomain(request.url, locationURL)) {
6426
+ for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
6427
+ requestOptions.headers.delete(name);
6428
+ }
6429
+ }
6430
+
6329
6431
  // HTTP-redirect fetch step 9
6330
6432
  if (response_.statusCode !== 303 && request.body && options_.body instanceof Stream.Readable) {
6331
6433
  reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
@@ -6364,8 +6466,13 @@ async function fetch(url, options_) {
6364
6466
  });
6365
6467
  }
6366
6468
 
6367
- let body = pipeline(response_, new PassThrough(), reject);
6469
+ let body = pipeline$1(response_, new PassThrough(), error => {
6470
+ if (error) {
6471
+ reject(error);
6472
+ }
6473
+ });
6368
6474
  // see https://github.com/nodejs/node/pull/29376
6475
+ /* c8 ignore next 3 */
6369
6476
  if (process.version < 'v12.10') {
6370
6477
  response_.on('aborted', abortAndFinalize);
6371
6478
  }
@@ -6409,7 +6516,11 @@ async function fetch(url, options_) {
6409
6516
 
6410
6517
  // For gzip
6411
6518
  if (codings === 'gzip' || codings === 'x-gzip') {
6412
- body = pipeline(body, zlib.createGunzip(zlibOptions), reject);
6519
+ body = pipeline$1(body, zlib.createGunzip(zlibOptions), error => {
6520
+ if (error) {
6521
+ reject(error);
6522
+ }
6523
+ });
6413
6524
  response = new Response(body, responseOptions);
6414
6525
  resolve(response);
6415
6526
  return;
@@ -6419,20 +6530,48 @@ async function fetch(url, options_) {
6419
6530
  if (codings === 'deflate' || codings === 'x-deflate') {
6420
6531
  // Handle the infamous raw deflate response from old servers
6421
6532
  // a hack for old IIS and Apache servers
6422
- const raw = pipeline(response_, new PassThrough(), reject);
6533
+ const raw = pipeline$1(response_, new PassThrough(), error => {
6534
+ if (error) {
6535
+ reject(error);
6536
+ }
6537
+ });
6423
6538
  raw.once('data', chunk => {
6424
6539
  // See http://stackoverflow.com/questions/37519828
6425
- body = (chunk[0] & 0x0F) === 0x08 ? pipeline(body, zlib.createInflate(), reject) : pipeline(body, zlib.createInflateRaw(), reject);
6540
+ if ((chunk[0] & 0x0F) === 0x08) {
6541
+ body = pipeline$1(body, zlib.createInflate(), error => {
6542
+ if (error) {
6543
+ reject(error);
6544
+ }
6545
+ });
6546
+ } else {
6547
+ body = pipeline$1(body, zlib.createInflateRaw(), error => {
6548
+ if (error) {
6549
+ reject(error);
6550
+ }
6551
+ });
6552
+ }
6426
6553
 
6427
6554
  response = new Response(body, responseOptions);
6428
6555
  resolve(response);
6429
6556
  });
6557
+ raw.once('end', () => {
6558
+ // Some old IIS servers return zero-length OK deflate responses, so
6559
+ // 'data' is never emitted. See https://github.com/node-fetch/node-fetch/pull/903
6560
+ if (!response) {
6561
+ response = new Response(body, responseOptions);
6562
+ resolve(response);
6563
+ }
6564
+ });
6430
6565
  return;
6431
6566
  }
6432
6567
 
6433
6568
  // For br
6434
6569
  if (codings === 'br') {
6435
- body = pipeline(body, zlib.createBrotliDecompress(), reject);
6570
+ body = pipeline$1(body, zlib.createBrotliDecompress(), error => {
6571
+ if (error) {
6572
+ reject(error);
6573
+ }
6574
+ });
6436
6575
  response = new Response(body, responseOptions);
6437
6576
  resolve(response);
6438
6577
  return;
@@ -6443,12 +6582,13 @@ async function fetch(url, options_) {
6443
6582
  resolve(response);
6444
6583
  });
6445
6584
 
6446
- writeToStream(request_, request);
6585
+ // eslint-disable-next-line promise/prefer-await-to-then
6586
+ writeToStream(request_, request).catch(reject);
6447
6587
  });
6448
6588
  }
6449
6589
 
6450
6590
  function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6451
- const LAST_CHUNK = Buffer.from('0\r\n\r\n');
6591
+ const LAST_CHUNK = Buffer$1.from('0\r\n\r\n');
6452
6592
 
6453
6593
  let isChunkedTransfer = false;
6454
6594
  let properLastChunkReceived = false;
@@ -6475,13 +6615,13 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6475
6615
  });
6476
6616
 
6477
6617
  socket.on('data', buf => {
6478
- properLastChunkReceived = Buffer.compare(buf.slice(-5), LAST_CHUNK) === 0;
6618
+ properLastChunkReceived = Buffer$1.compare(buf.slice(-5), LAST_CHUNK) === 0;
6479
6619
 
6480
6620
  // Sometimes final 0-length chunk and end of message code are in separate packets
6481
6621
  if (!properLastChunkReceived && previousChunk) {
6482
6622
  properLastChunkReceived = (
6483
- Buffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 &&
6484
- Buffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0
6623
+ Buffer$1.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 &&
6624
+ Buffer$1.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0
6485
6625
  );
6486
6626
  }
6487
6627