fetch-nodeshim 0.3.0 → 0.4.0-canary-2b29583b1a984d5ee8a9b457f7c00942dca24790

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