fetch-nodeshim 0.3.0 → 0.4.0-canary-eaf68db8156953f9940d5b9be8744b077581ca58

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/minifetch.js CHANGED
@@ -6,28 +6,30 @@ var e = require("node:stream");
6
6
 
7
7
  var t = require("node:https");
8
8
 
9
- var r = require("node:http");
9
+ var n = require("node:http");
10
10
 
11
- var n = require("node:url");
11
+ var o = require("node:url");
12
12
 
13
- var a = require("node:util/types");
13
+ var r = require("node:util/types");
14
14
 
15
- var o = require("node:crypto");
15
+ var s = require("node:crypto");
16
16
 
17
- var s = require("node:buffer");
17
+ var a = require("node:buffer");
18
18
 
19
19
  var i = require("node:zlib");
20
20
 
21
+ var c = require("node:net");
22
+
21
23
  function _interopNamespaceDefault(e) {
22
24
  var t = Object.create(null);
23
25
  if (e) {
24
- Object.keys(e).forEach((function(r) {
25
- if ("default" !== r) {
26
- var n = Object.getOwnPropertyDescriptor(e, r);
27
- Object.defineProperty(t, r, n.get ? n : {
26
+ Object.keys(e).forEach((function(n) {
27
+ if ("default" !== n) {
28
+ var o = Object.getOwnPropertyDescriptor(e, n);
29
+ Object.defineProperty(t, n, o.get ? o : {
28
30
  enumerable: !0,
29
31
  get: function() {
30
- return e[r];
32
+ return e[n];
31
33
  }
32
34
  });
33
35
  }
@@ -37,156 +39,158 @@ function _interopNamespaceDefault(e) {
37
39
  return t;
38
40
  }
39
41
 
40
- var f = _interopNamespaceDefault(t);
42
+ var l = _interopNamespaceDefault(t);
41
43
 
42
- var l = _interopNamespaceDefault(r);
44
+ var f = _interopNamespaceDefault(n);
43
45
 
44
- var u = _interopNamespaceDefault(n);
46
+ var u = _interopNamespaceDefault(o);
45
47
 
46
- var c = _interopNamespaceDefault(s);
48
+ var p = _interopNamespaceDefault(a);
47
49
 
48
50
  var d = _interopNamespaceDefault(i);
49
51
 
50
- var p = globalThis.File || c.File;
52
+ var y = _interopNamespaceDefault(c);
53
+
54
+ const h = globalThis.File || p.File;
51
55
 
52
56
  if (void 0 === globalThis.File) {
53
- globalThis.File = p;
57
+ globalThis.File = h;
54
58
  }
55
59
 
56
- var y = Blob;
60
+ const m = Blob;
57
61
 
58
- var h = URLSearchParams;
62
+ const b = URLSearchParams;
59
63
 
60
- var v = URL;
64
+ const g = URL;
61
65
 
62
- var b = Request;
66
+ const w = Request;
63
67
 
64
- var m = Response;
68
+ const v = Response;
65
69
 
66
- var g = Headers;
70
+ const T = Headers;
67
71
 
68
- var w = FormData;
72
+ const _ = FormData;
69
73
 
70
- var T = "\r\n";
74
+ const L = "\r\n";
71
75
 
72
- var L = "-".repeat(2);
76
+ const x = "-".repeat(2);
73
77
 
74
- var isReadable = t => e.Readable.isReadable(t);
78
+ const isReadable = t => e.Readable.isReadable(t);
75
79
 
76
- var isReadableStream = e => "object" == typeof e && "function" == typeof e.getReader && "function" == typeof e.cancel && "function" == typeof e.tee;
80
+ const isReadableStream = e => "object" == typeof e && "function" == typeof e.getReader && "function" == typeof e.cancel && "function" == typeof e.tee;
77
81
 
78
- var isBlob = e => {
82
+ const isBlob = e => {
79
83
  if ("object" == typeof e && "function" == typeof e.arrayBuffer && "string" == typeof e.type && "function" == typeof e.stream && "function" == typeof e.constructor) {
80
- var t = e[Symbol.toStringTag];
84
+ const t = e[Symbol.toStringTag];
81
85
  return t.startsWith("Blob") || t.startsWith("File");
82
86
  } else {
83
87
  return !1;
84
88
  }
85
89
  };
86
90
 
87
- var getFormHeader = (e, t, r) => {
88
- var n = `${L}${e}${T}`;
89
- n += `Content-Disposition: form-data; name="${t}"`;
90
- if (isBlob(r)) {
91
- n += `; filename="${r.name ?? "blob"}"${T}`;
92
- n += `Content-Type: ${r.type || "application/octet-stream"}`;
91
+ const getFormHeader = (e, t, n) => {
92
+ let o = `${x}${e}${L}`;
93
+ o += `Content-Disposition: form-data; name="${t}"`;
94
+ if (isBlob(n)) {
95
+ o += `; filename="${n.name ?? "blob"}"${L}`;
96
+ o += `Content-Type: ${n.type || "application/octet-stream"}`;
93
97
  }
94
- return `${n}${T}${T}`;
98
+ return `${o}${L}${L}`;
95
99
  };
96
100
 
97
- var getFormFooter = e => `${L}${e}${L}${T}${T}`;
101
+ const getFormFooter = e => `${x}${e}${x}${L}${L}`;
98
102
 
99
- var _ = new TextEncoder;
103
+ const R = new TextEncoder;
100
104
 
101
- var extractBody = t => {
102
- var r = null;
103
- var n;
104
- var s = null;
105
+ const extractBody = t => {
106
+ let n = null;
107
+ let o;
108
+ let a = null;
105
109
  if (null == t) {
106
- n = null;
107
- s = 0;
110
+ o = null;
111
+ a = 0;
108
112
  } else if ("string" == typeof t) {
109
- var i = _.encode(`${t}`);
110
- r = "text/plain;charset=UTF-8";
111
- s = i.byteLength;
112
- n = i;
113
+ const e = R.encode(`${t}`);
114
+ n = "text/plain;charset=UTF-8";
115
+ a = e.byteLength;
116
+ o = e;
113
117
  } else if ((e => "object" == typeof e && "function" == typeof e.append && "function" == typeof e.delete && "function" == typeof e.get && "function" == typeof e.getAll && "function" == typeof e.has && "function" == typeof e.set && "function" == typeof e.sort && "URLSearchParams" === e[Symbol.toStringTag])(t)) {
114
- var f = _.encode(t.toString());
115
- n = f;
116
- s = f.byteLength;
117
- r = "application/x-www-form-urlencoded;charset=UTF-8";
118
+ const e = R.encode(t.toString());
119
+ o = e;
120
+ a = e.byteLength;
121
+ n = "application/x-www-form-urlencoded;charset=UTF-8";
118
122
  } else if (isBlob(t)) {
119
- s = t.size;
120
- r = t.type || null;
121
- n = t.stream();
123
+ a = t.size;
124
+ n = t.type || null;
125
+ o = t.stream();
122
126
  } else if (t instanceof Uint8Array) {
123
- n = t;
124
- s = t.byteLength;
125
- } else if (a.isAnyArrayBuffer(t)) {
126
- var l = new Uint8Array(t);
127
- n = l;
128
- s = l.byteLength;
127
+ o = t;
128
+ a = t.byteLength;
129
+ } else if (r.isAnyArrayBuffer(t)) {
130
+ const e = new Uint8Array(t);
131
+ o = e;
132
+ a = e.byteLength;
129
133
  } else if (ArrayBuffer.isView(t)) {
130
- var u = new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
131
- n = u;
132
- s = u.byteLength;
134
+ const e = new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
135
+ o = e;
136
+ a = e.byteLength;
133
137
  } else if (isReadableStream(t)) {
134
- n = t;
138
+ o = t;
135
139
  } else if ((e => "object" == typeof e && "function" == typeof e.append && "function" == typeof e.set && "function" == typeof e.get && "function" == typeof e.getAll && "function" == typeof e.delete && "function" == typeof e.keys && "function" == typeof e.values && "function" == typeof e.entries && "function" == typeof e.constructor && "FormData" === e[Symbol.toStringTag])(t)) {
136
- var c = `formdata-${o.randomBytes(8).toString("hex")}`;
137
- r = `multipart/form-data; boundary=${c}`;
138
- s = ((e, t) => {
139
- var r = Buffer.byteLength(getFormFooter(t));
140
- for (var [n, a] of e) {
141
- r += Buffer.byteLength(getFormHeader(t, n, a)) + (isBlob(a) ? a.size : Buffer.byteLength(`${a}`)) + 2;
140
+ const r = `formdata-${s.randomBytes(8).toString("hex")}`;
141
+ n = `multipart/form-data; boundary=${r}`;
142
+ a = ((e, t) => {
143
+ let n = Buffer.byteLength(getFormFooter(t));
144
+ for (const [o, r] of e) {
145
+ n += Buffer.byteLength(getFormHeader(t, o, r)) + (isBlob(r) ? r.size : Buffer.byteLength(`${r}`)) + 2;
142
146
  }
143
- return r;
144
- })(t, c);
145
- n = e.Readable.from(async function* generatorOfFormData(e, t) {
146
- var r = new TextEncoder;
147
- for (var [n, a] of e) {
148
- if (isBlob(a)) {
149
- yield r.encode(getFormHeader(t, n, a));
150
- yield* a.stream();
151
- yield r.encode(T);
147
+ return n;
148
+ })(t, r);
149
+ o = e.Readable.from(async function* generatorOfFormData(e, t) {
150
+ const n = new TextEncoder;
151
+ for (const [o, r] of e) {
152
+ if (isBlob(r)) {
153
+ yield n.encode(getFormHeader(t, o, r));
154
+ yield* r.stream();
155
+ yield n.encode(L);
152
156
  } else {
153
- yield r.encode(getFormHeader(t, n, a) + a + T);
157
+ yield n.encode(getFormHeader(t, o, r) + r + L);
154
158
  }
155
159
  }
156
- yield r.encode(getFormFooter(t));
157
- }(t, c));
160
+ yield n.encode(getFormFooter(t));
161
+ }(t, r));
158
162
  } else if ((t => "function" == typeof t.getBoundary && "function" == typeof t.hasKnownLength && "function" == typeof t.getLengthSync && e.Readable.isReadable(t))(t)) {
159
- r = `multipart/form-data; boundary=${t.getBoundary()}`;
160
- s = t.hasKnownLength() ? t.getLengthSync() : null;
161
- n = t;
163
+ n = `multipart/form-data; boundary=${t.getBoundary()}`;
164
+ a = t.hasKnownLength() ? t.getLengthSync() : null;
165
+ o = t;
162
166
  } else if (isReadable(t)) {
163
- n = t;
167
+ o = t;
164
168
  } else if ((e => "function" == typeof e[Symbol.asyncIterator] || "function" == typeof e[Symbol.iterator])(t)) {
165
- n = e.Readable.from(t);
169
+ o = e.Readable.from(t);
166
170
  } else {
167
- var d = _.encode(`${t}`);
168
- r = "text/plain;charset=UTF-8";
169
- n = d;
170
- s = d.byteLength;
171
+ const e = R.encode(`${t}`);
172
+ n = "text/plain;charset=UTF-8";
173
+ o = e;
174
+ a = e.byteLength;
171
175
  }
172
176
  return {
173
- contentLength: s,
174
- contentType: r,
175
- body: n
177
+ contentLength: a,
178
+ contentType: n,
179
+ body: o
176
180
  };
177
181
  };
178
182
 
179
- var S = Symbol("kBodyInternals");
183
+ const $ = Symbol("kBodyInternals");
180
184
 
181
185
  class InflateStream extends e.Transform {
182
186
  constructor(e) {
183
187
  super();
184
188
  this._opts = e;
185
189
  }
186
- _transform(e, t, r) {
190
+ _transform(e, t, n) {
187
191
  if (!this._inflate) {
188
192
  if (0 === e.length) {
189
- r();
193
+ n();
190
194
  return;
191
195
  }
192
196
  this._inflate = 8 == (15 & e[0]) ? d.createInflate(this._opts) : d.createInflateRaw(this._opts);
@@ -194,7 +198,7 @@ class InflateStream extends e.Transform {
194
198
  this._inflate.on("end", (() => this.push(null)));
195
199
  this._inflate.on("error", (e => this.destroy(e)));
196
200
  }
197
- this._inflate.write(e, t, r);
201
+ this._inflate.write(e, t, n);
198
202
  }
199
203
  _final(e) {
200
204
  if (this._inflate) {
@@ -205,15 +209,149 @@ class InflateStream extends e.Transform {
205
209
  }
206
210
  }
207
211
 
208
- var headersOfRawHeaders = e => {
209
- var t = new Headers;
210
- for (var r = 0; r < e.length; r += 2) {
211
- t.set(e[r], e[r + 1]);
212
+ const getHttpProxyUrl = () => process.env.HTTP_PROXY ?? process.env.http_proxy;
213
+
214
+ const createProxyPattern = e => {
215
+ if (!(e = e.trim().replace(/\./g, "\\.").replace(/\*/g, "[w.]+")).startsWith(".")) {
216
+ e = `^${e}`;
217
+ }
218
+ if (!e.endsWith(".") || e.includes(":")) {
219
+ e += "$";
220
+ }
221
+ return new RegExp(e, "i");
222
+ };
223
+
224
+ const matchesNoProxy = e => {
225
+ const t = process.env.NO_PROXY ?? process.env.no_proxy;
226
+ if ("*" === t || "1" === t || "true" === t) {
227
+ return !0;
228
+ } else if (t) {
229
+ for (const n of t.split(",")) {
230
+ const t = createProxyPattern(n);
231
+ const o = e.hostname || e.host;
232
+ const r = o && `${o}:${e.port || e.defaultPort || 80}`;
233
+ if (o && t.test(o) || r && t.test(r)) {
234
+ return !0;
235
+ }
236
+ }
237
+ return !1;
238
+ } else {
239
+ return !1;
240
+ }
241
+ };
242
+
243
+ const P = {
244
+ keepAlive: !0,
245
+ keepAliveMsecs: 1e3
246
+ };
247
+
248
+ let A;
249
+
250
+ let S;
251
+
252
+ let C;
253
+
254
+ let E;
255
+
256
+ const createRequestOptions = (e, t, n) => {
257
+ const o = {
258
+ host: `${n.host}:${n.port}`,
259
+ connection: t ? "keep-alive" : "close"
260
+ };
261
+ if (e.username || e.password) {
262
+ const t = decodeURIComponent(e.username || "");
263
+ const n = decodeURIComponent(e.password || "");
264
+ const r = Buffer.from(`${t}:${n}`).toString("base64");
265
+ o["proxy-authorization"] = `Basic ${r}`;
266
+ }
267
+ return {
268
+ method: "CONNECT",
269
+ host: e.hostname,
270
+ port: e.port,
271
+ path: `${n.host}:${n.port}`,
272
+ setHost: !1,
273
+ agent: !1,
274
+ proxyEnv: {},
275
+ timeout: 8e3,
276
+ headers: o,
277
+ servername: "https:" === e.protocol ? e.hostname : void 0
278
+ };
279
+ };
280
+
281
+ class HttpProxyAgent extends f.Agent {
282
+ constructor(e, t) {
283
+ super(t);
284
+ this._proxy = e;
285
+ this._keepAlive = !!t.keepAlive;
286
+ }
287
+ createConnection(e, t) {
288
+ const n = ("http:" === this._proxy.protocol ? f : l).request(createRequestOptions(this._proxy, this._keepAlive, e));
289
+ n.once("connect", ((e, o, r) => {
290
+ n.removeAllListeners();
291
+ o.removeAllListeners();
292
+ if (200 === e.statusCode) {
293
+ t(null, o);
294
+ } else {
295
+ o.destroy();
296
+ t(new Error(`HTTP Proxy Network Error: ${e.statusMessage || e.statusCode}`), null);
297
+ }
298
+ }));
299
+ n.once("timeout", (() => {
300
+ n.destroy(new Error("HTTP Proxy timed out"));
301
+ }));
302
+ n.once("error", (e => {
303
+ n.removeAllListeners();
304
+ t(e, null);
305
+ }));
306
+ n.end();
307
+ }
308
+ }
309
+
310
+ class HttpsProxyAgent extends l.Agent {
311
+ constructor(e, t) {
312
+ super(t);
313
+ this._proxy = e;
314
+ this._keepAlive = !!t.keepAlive;
315
+ }
316
+ createConnection(e, t) {
317
+ const n = ("http:" === this._proxy.protocol ? f : l).request(createRequestOptions(this._proxy, this._keepAlive, e));
318
+ n.once("connect", ((o, r, s) => {
319
+ n.removeAllListeners();
320
+ r.removeAllListeners();
321
+ if (200 === o.statusCode) {
322
+ const n = {
323
+ ...e,
324
+ socket: r
325
+ };
326
+ y._normalizeArgs(n);
327
+ const o = super.createConnection(n);
328
+ t?.(null, o);
329
+ } else {
330
+ r.destroy();
331
+ t?.(new Error(`HTTP Proxy Network Error: ${o.statusMessage || o.statusCode}`), null);
332
+ }
333
+ }));
334
+ n.once("timeout", (() => {
335
+ n.destroy(new Error("HTTP Proxy timed out"));
336
+ }));
337
+ n.once("error", (e => {
338
+ n.removeAllListeners();
339
+ t?.(e, null);
340
+ }));
341
+ n.end();
342
+ return n.socket;
343
+ }
344
+ }
345
+
346
+ const headersOfRawHeaders = e => {
347
+ const t = new Headers;
348
+ for (let n = 0; n < e.length; n += 2) {
349
+ t.set(e[n], e[n + 1]);
212
350
  }
213
351
  return t;
214
352
  };
215
353
 
216
- var methodToHttpOption = e => {
354
+ const methodToHttpOption = e => {
217
355
  switch (e) {
218
356
  case "CONNECT":
219
357
  case "TRACE":
@@ -225,8 +363,8 @@ var methodToHttpOption = e => {
225
363
  }
226
364
  };
227
365
 
228
- var urlToHttpOptions = e => {
229
- var t = new v(e);
366
+ const urlToHttpOptions = e => {
367
+ const t = new g(e);
230
368
  switch (t.protocol) {
231
369
  case "http:":
232
370
  case "https:":
@@ -237,12 +375,12 @@ var urlToHttpOptions = e => {
237
375
  }
238
376
  };
239
377
 
240
- async function _fetch(t, r) {
241
- var n = (e => null != e && "object" == typeof e && "body" in e)(t);
242
- var a = n ? t.url : t;
243
- var o = n ? t.body : r?.body || null;
244
- var s = n ? t.signal : r?.signal || void 0;
245
- var i = (e => {
378
+ async function _fetch(t, n) {
379
+ const o = (e => null != e && "object" == typeof e && "body" in e)(t);
380
+ const r = o ? t.url : t;
381
+ const s = o ? t.body : n?.body || null;
382
+ const a = o ? t.signal : n?.signal || void 0;
383
+ const i = (e => {
246
384
  switch (e) {
247
385
  case "follow":
248
386
  case "manual":
@@ -255,72 +393,115 @@ async function _fetch(t, r) {
255
393
  default:
256
394
  throw new TypeError(`Request constructor: ${e} is not an accepted type. Expected one of follow, manual, error.`);
257
395
  }
258
- })(n ? t.redirect : r?.redirect);
259
- var u = new v(a);
260
- var c = extractBody(o);
261
- var p = 0;
262
- var y = new Headers(r?.headers || (n ? t.headers : void 0));
263
- var h = {
264
- ...urlToHttpOptions(u),
265
- method: methodToHttpOption(n ? t.method : r?.method),
266
- signal: s
396
+ })(o ? t.redirect : n?.redirect);
397
+ let c = new g(r);
398
+ let u = extractBody(s);
399
+ let p = 0;
400
+ const y = new Headers(n?.headers || (o ? t.headers : void 0));
401
+ const h = {
402
+ ...urlToHttpOptions(c),
403
+ method: methodToHttpOption(o ? t.method : n?.method),
404
+ signal: a
267
405
  };
268
- return await new Promise((function _call(t, r) {
269
- var n = h.method;
270
- var a = ("https:" === h.protocol ? f : l).request(h);
271
- a.on("response", (a => {
272
- a.setTimeout(0);
273
- var f = {
274
- status: a.statusCode,
275
- statusText: a.statusMessage,
276
- headers: headersOfRawHeaders(a.rawHeaders)
406
+ h.agent = "https:" === h.protocol ? (e => {
407
+ const t = process.env.HTTPS_PROXY ?? process.env.https_proxy ?? getHttpProxyUrl();
408
+ if (!t) {
409
+ E = void 0;
410
+ return;
411
+ } else if (matchesNoProxy(e)) {
412
+ return;
413
+ } else if (!C || C !== t) {
414
+ E = void 0;
415
+ try {
416
+ C = t;
417
+ E = new HttpsProxyAgent(new URL(t), P);
418
+ } catch (e) {
419
+ const n = new Error(`Invalid HTTPS_PROXY URL: "${t}".\n` + e?.message || e);
420
+ n.cause = e;
421
+ throw n;
422
+ }
423
+ return E;
424
+ } else {
425
+ return E;
426
+ }
427
+ })(h) : (e => {
428
+ const t = getHttpProxyUrl();
429
+ if (!t) {
430
+ S = void 0;
431
+ return;
432
+ } else if (matchesNoProxy(e)) {
433
+ return;
434
+ } else if (!A || A !== t) {
435
+ S = void 0;
436
+ try {
437
+ A = t;
438
+ S = new HttpProxyAgent(new URL(t), P);
439
+ } catch (e) {
440
+ const n = new Error(`Invalid HTTP_PROXY URL: "${t}".\n` + e?.message || e);
441
+ n.cause = e;
442
+ throw n;
443
+ }
444
+ return S;
445
+ } else {
446
+ return S;
447
+ }
448
+ })(h);
449
+ return await new Promise((function _call(t, n) {
450
+ const o = h.method;
451
+ const r = ("https:" === h.protocol ? l : f).request(h);
452
+ r.on("response", (r => {
453
+ r.setTimeout(0);
454
+ const l = {
455
+ status: r.statusCode,
456
+ statusText: r.statusMessage,
457
+ headers: headersOfRawHeaders(r.rawHeaders)
277
458
  };
278
- if (301 === (g = f.status) || 302 === g || 303 === g || 307 === g || 308 === g) {
279
- var l = f.headers.get("Location");
280
- var b = null != l ? new v(l, u) : null;
459
+ if (301 === (f = l.status) || 302 === f || 303 === f || 307 === f || 308 === f) {
460
+ const e = l.headers.get("Location");
461
+ const r = null != e ? new g(e, c) : null;
281
462
  if ("error" === i) {
282
- r(new Error("URI requested responds with a redirect, redirect mode is set to error"));
463
+ n(new Error("URI requested responds with a redirect, redirect mode is set to error"));
283
464
  return;
284
- } else if ("manual" === i && null !== b) {
285
- f.headers.set("Location", b.toString());
286
- } else if ("follow" === i && null !== b) {
465
+ } else if ("manual" === i && null !== r) {
466
+ l.headers.set("Location", r.toString());
467
+ } else if ("follow" === i && null !== r) {
287
468
  if (++p > 20) {
288
- r(new Error(`maximum redirect reached at: ${u}`));
469
+ n(new Error(`maximum redirect reached at: ${c}`));
289
470
  return;
290
- } else if ("http:" !== b.protocol && "https:" !== b.protocol) {
291
- r(new Error("URL scheme must be a HTTP(S) scheme"));
471
+ } else if ("http:" !== r.protocol && "https:" !== r.protocol) {
472
+ n(new Error("URL scheme must be a HTTP(S) scheme"));
292
473
  return;
293
474
  }
294
- if (303 === f.status || (301 === f.status || 302 === f.status) && "POST" === n) {
295
- c = extractBody(null);
475
+ if (303 === l.status || (301 === l.status || 302 === l.status) && "POST" === o) {
476
+ u = extractBody(null);
296
477
  h.method = "GET";
297
478
  y.delete("Content-Length");
298
- } else if (null != c.body && null == c.contentLength) {
299
- r(new Error("Cannot follow redirect with a streamed body"));
479
+ } else if (null != u.body && null == u.contentLength) {
480
+ n(new Error("Cannot follow redirect with a streamed body"));
300
481
  return;
301
482
  } else {
302
- c = extractBody(o);
483
+ u = extractBody(s);
303
484
  }
304
- Object.assign(h, urlToHttpOptions(u = b));
305
- return _call(t, r);
485
+ Object.assign(h, urlToHttpOptions(c = r));
486
+ return _call(t, n);
306
487
  }
307
488
  }
308
- var g;
309
- var destroy = e => {
310
- s?.removeEventListener("abort", destroy);
489
+ var f;
490
+ const destroy = e => {
491
+ a?.removeEventListener("abort", destroy);
311
492
  if (e) {
312
- a.destroy(s?.aborted ? s.reason : e);
313
- r(s?.aborted ? s.reason : e);
493
+ r.destroy(a?.aborted ? a.reason : e);
494
+ n(a?.aborted ? a.reason : e);
314
495
  }
315
496
  };
316
- s?.addEventListener("abort", destroy);
317
- var w = a;
318
- var T = f.headers.get("Content-Encoding")?.toLowerCase();
319
- if ("HEAD" === n || 204 === f.status || 304 === f.status) {
320
- w = null;
321
- } else if (null != T) {
322
- f.headers.set("Content-Encoding", T);
323
- w = e.pipeline(w, (t => {
497
+ a?.addEventListener("abort", destroy);
498
+ let m = r;
499
+ const b = l.headers.get("Content-Encoding")?.toLowerCase();
500
+ if ("HEAD" === o || 204 === l.status || 304 === l.status) {
501
+ m = null;
502
+ } else if (null != b) {
503
+ l.headers.set("Content-Encoding", b);
504
+ m = e.pipeline(m, (t => {
324
505
  switch (t) {
325
506
  case "br":
326
507
  return d.createBrotliDecompress({
@@ -345,78 +526,78 @@ async function _fetch(t, r) {
345
526
  default:
346
527
  return new e.PassThrough;
347
528
  }
348
- })(T), destroy);
529
+ })(b), destroy);
349
530
  }
350
- t(function createResponse(e, t, r) {
351
- var n = new m(e, t);
352
- Object.defineProperty(n, "url", {
353
- value: r.url
531
+ t(function createResponse(e, t, n) {
532
+ const o = new v(e, t);
533
+ Object.defineProperty(o, "url", {
534
+ value: n.url
354
535
  });
355
- if ("default" !== r.type) {
356
- Object.defineProperty(n, "type", {
357
- value: r.type
536
+ if ("default" !== n.type) {
537
+ Object.defineProperty(o, "type", {
538
+ value: n.type
358
539
  });
359
540
  }
360
- if (r.redirected) {
361
- Object.defineProperty(n, "redirected", {
362
- value: r.redirected
541
+ if (n.redirected) {
542
+ Object.defineProperty(o, "redirected", {
543
+ value: n.redirected
363
544
  });
364
545
  }
365
- return n;
366
- }(w, f, {
546
+ return o;
547
+ }(m, l, {
367
548
  type: "default",
368
- url: u.toString(),
549
+ url: c.toString(),
369
550
  redirected: p > 0
370
551
  }));
371
552
  }));
372
- a.on("error", r);
553
+ r.on("error", n);
373
554
  if (!y.has("Accept")) {
374
555
  y.set("Accept", "*/*");
375
556
  }
376
- if (c.contentType) {
377
- y.set("Content-Type", c.contentType);
557
+ if (u.contentType) {
558
+ y.set("Content-Type", u.contentType);
378
559
  }
379
- if (null == c.body && ("POST" === n || "PUT" === n)) {
560
+ if (null == u.body && ("POST" === o || "PUT" === o)) {
380
561
  y.set("Content-Length", "0");
381
- } else if (null != c.body && null != c.contentLength) {
382
- y.set("Content-Length", `${c.contentLength}`);
562
+ } else if (null != u.body && null != u.contentLength) {
563
+ y.set("Content-Length", `${u.contentLength}`);
383
564
  }
384
565
  ((e, t) => {
385
566
  if ("function" == typeof e.setHeaders) {
386
567
  e.setHeaders(t);
387
568
  } else {
388
- for (var [r, n] of t) {
389
- e.setHeader(r, n);
569
+ for (const [n, o] of t) {
570
+ e.setHeader(n, o);
390
571
  }
391
572
  }
392
- })(a, y);
393
- if (null == c.body) {
394
- a.end();
395
- } else if (c.body instanceof Uint8Array) {
396
- a.write(c.body);
397
- a.end();
573
+ })(r, y);
574
+ if (null == u.body) {
575
+ r.end();
576
+ } else if (u.body instanceof Uint8Array) {
577
+ r.write(u.body);
578
+ r.end();
398
579
  } else {
399
- var b = c.body instanceof e.Stream ? c.body : e.Readable.fromWeb(c.body);
400
- e.pipeline(b, a, (e => {
580
+ const t = u.body instanceof e.Stream ? u.body : e.Readable.fromWeb(u.body);
581
+ e.pipeline(t, r, (e => {
401
582
  if (e) {
402
- r(e);
583
+ n(e);
403
584
  }
404
585
  }));
405
586
  }
406
587
  }));
407
588
  }
408
589
 
409
- exports.Blob = y;
590
+ exports.Blob = m;
410
591
 
411
592
  exports.Body = class Body {
412
593
  constructor(e) {
413
- this[S] = extractBody(e);
594
+ this[$] = extractBody(e);
414
595
  }
415
596
  get body() {
416
- return this[S].body;
597
+ return this[$].body;
417
598
  }
418
599
  get bodyUsed() {
419
- var {body: t} = this[S];
600
+ const {body: t} = this[$];
420
601
  if (isReadable(t)) {
421
602
  return e.Readable.isDisturbed(t);
422
603
  } else if (isReadableStream(t)) {
@@ -426,30 +607,30 @@ exports.Body = class Body {
426
607
  }
427
608
  }
428
609
  async arrayBuffer() {
429
- var {body: e} = this[S];
430
- return a.isAnyArrayBuffer(e) ? e : new m(this.body).arrayBuffer();
610
+ const {body: e} = this[$];
611
+ return r.isAnyArrayBuffer(e) ? e : new v(this.body).arrayBuffer();
431
612
  }
432
613
  async formData() {
433
- var {body: e, contentLength: t, contentType: r} = this[S];
434
- var n = {};
614
+ const {body: e, contentLength: t, contentType: n} = this[$];
615
+ const o = {};
435
616
  if (t) {
436
- n["Content-Length"] = t;
617
+ o["Content-Length"] = t;
437
618
  }
438
- if (r) {
439
- n["Content-Type"] = r;
619
+ if (n) {
620
+ o["Content-Type"] = n;
440
621
  }
441
- return new m(e, {
442
- headers: n
622
+ return new v(e, {
623
+ headers: o
443
624
  }).formData();
444
625
  }
445
626
  async blob() {
446
- var {contentType: e} = this[S];
447
- return new y([ await this.arrayBuffer() ], {
627
+ const {contentType: e} = this[$];
628
+ return new m([ await this.arrayBuffer() ], {
448
629
  type: e ?? void 0
449
630
  });
450
631
  }
451
632
  async json() {
452
- var e = await this.text();
633
+ const e = await this.text();
453
634
  return JSON.parse(e);
454
635
  }
455
636
  async text() {
@@ -457,19 +638,19 @@ exports.Body = class Body {
457
638
  }
458
639
  };
459
640
 
460
- exports.File = p;
641
+ exports.File = h;
461
642
 
462
- exports.FormData = w;
643
+ exports.FormData = _;
463
644
 
464
- exports.Headers = g;
645
+ exports.Headers = T;
465
646
 
466
- exports.Request = b;
647
+ exports.Request = w;
467
648
 
468
- exports.Response = m;
649
+ exports.Response = v;
469
650
 
470
- exports.URL = v;
651
+ exports.URL = g;
471
652
 
472
- exports.URLSearchParams = h;
653
+ exports.URLSearchParams = b;
473
654
 
474
655
  exports.default = _fetch;
475
656