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