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