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/CHANGELOG.md +12 -0
- package/dist/minifetch.js +395 -214
- package/dist/minifetch.js.map +1 -1
- package/dist/minifetch.mjs +360 -181
- package/dist/minifetch.mjs.map +1 -1
- package/package.json +3 -2
package/dist/minifetch.mjs
CHANGED
|
@@ -1,159 +1,161 @@
|
|
|
1
|
-
import { Readable as e, PassThrough as t, Transform as
|
|
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
|
|
3
|
+
import * as r from "node:https";
|
|
4
4
|
|
|
5
|
-
import * as
|
|
5
|
+
import * as i from "node:http";
|
|
6
6
|
|
|
7
|
-
import * as
|
|
7
|
+
import * as c from "node:url";
|
|
8
8
|
|
|
9
|
-
import { isAnyArrayBuffer as
|
|
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
|
|
13
|
+
import * as f from "node:buffer";
|
|
14
14
|
|
|
15
15
|
import * as u from "node:zlib";
|
|
16
16
|
|
|
17
|
-
|
|
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 =
|
|
22
|
+
globalThis.File = p;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
const y = Blob;
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
const h = URLSearchParams;
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
const m = URL;
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
const g = Request;
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
const b = Response;
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
const w = Headers;
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
const T = FormData;
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
const L = "\r\n";
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
const _ = "-".repeat(2);
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
const isReadable = t => e.isReadable(t);
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
const isReadableStream = e => "object" == typeof e && "function" == typeof e.getReader && "function" == typeof e.cancel && "function" == typeof e.tee;
|
|
44
46
|
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
+
const getFormHeader = (e, t, o) => {
|
|
57
|
+
let n = `${_}${e}${L}`;
|
|
56
58
|
n += `Content-Disposition: form-data; name="${t}"`;
|
|
57
|
-
if (isBlob(
|
|
58
|
-
n += `; filename="${
|
|
59
|
-
n += `Content-Type: ${
|
|
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}${
|
|
63
|
+
return `${n}${L}${L}`;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
const getFormFooter = e => `${_}${e}${_}${L}${L}`;
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
const v = new TextEncoder;
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
+
s = 0;
|
|
75
77
|
} else if ("string" == typeof t) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
n =
|
|
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
|
-
|
|
82
|
-
n =
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
92
|
-
} else if (
|
|
93
|
-
|
|
94
|
-
n =
|
|
95
|
-
|
|
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
|
-
|
|
98
|
-
n =
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for (
|
|
108
|
-
|
|
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
|
|
111
|
-
})(t,
|
|
112
|
+
return o;
|
|
113
|
+
})(t, r);
|
|
112
114
|
n = e.from(async function* generatorOfFormData(e, t) {
|
|
113
|
-
|
|
114
|
-
for (
|
|
115
|
-
if (isBlob(
|
|
116
|
-
yield
|
|
117
|
-
yield*
|
|
118
|
-
yield
|
|
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
|
|
122
|
+
yield o.encode(getFormHeader(t, n, s) + s + L);
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
yield
|
|
124
|
-
}(t,
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
n =
|
|
137
|
-
|
|
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:
|
|
141
|
-
contentType:
|
|
142
|
+
contentLength: s,
|
|
143
|
+
contentType: o,
|
|
142
144
|
body: n
|
|
143
145
|
};
|
|
144
146
|
};
|
|
145
147
|
|
|
146
|
-
|
|
148
|
+
const $ = Symbol("kBodyInternals");
|
|
147
149
|
|
|
148
150
|
class Body {
|
|
149
151
|
constructor(e) {
|
|
150
|
-
this[
|
|
152
|
+
this[$] = extractBody(e);
|
|
151
153
|
}
|
|
152
154
|
get body() {
|
|
153
|
-
return this[
|
|
155
|
+
return this[$].body;
|
|
154
156
|
}
|
|
155
157
|
get bodyUsed() {
|
|
156
|
-
|
|
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
|
-
|
|
167
|
-
return
|
|
168
|
+
const {body: e} = this[$];
|
|
169
|
+
return a(e) ? e : new b(this.body).arrayBuffer();
|
|
168
170
|
}
|
|
169
171
|
async formData() {
|
|
170
|
-
|
|
171
|
-
|
|
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 (
|
|
176
|
-
n["Content-Type"] =
|
|
177
|
+
if (o) {
|
|
178
|
+
n["Content-Type"] = o;
|
|
177
179
|
}
|
|
178
|
-
return new
|
|
180
|
+
return new b(e, {
|
|
179
181
|
headers: n
|
|
180
182
|
}).formData();
|
|
181
183
|
}
|
|
182
184
|
async blob() {
|
|
183
|
-
|
|
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
|
-
|
|
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
|
|
199
|
+
class InflateStream extends o {
|
|
198
200
|
constructor(e) {
|
|
199
201
|
super();
|
|
200
202
|
this._opts = e;
|
|
201
203
|
}
|
|
202
|
-
_transform(e, t,
|
|
204
|
+
_transform(e, t, o) {
|
|
203
205
|
if (!this._inflate) {
|
|
204
206
|
if (0 === e.length) {
|
|
205
|
-
|
|
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,
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
|
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(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
})(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
...urlToHttpOptions(
|
|
281
|
-
method: methodToHttpOption(
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
468
|
+
const s = {
|
|
290
469
|
status: e.statusCode,
|
|
291
470
|
statusText: e.statusMessage,
|
|
292
471
|
headers: headersOfRawHeaders(e.rawHeaders)
|
|
293
472
|
};
|
|
294
|
-
if (301 === (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if ("error" ===
|
|
298
|
-
|
|
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" ===
|
|
301
|
-
|
|
302
|
-
} else if ("follow" ===
|
|
303
|
-
if (++
|
|
304
|
-
|
|
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:" !==
|
|
307
|
-
|
|
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 ===
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
} else if (null !=
|
|
315
|
-
|
|
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
|
-
|
|
497
|
+
h = extractBody(f);
|
|
319
498
|
}
|
|
320
|
-
Object.assign(
|
|
321
|
-
return _call(
|
|
499
|
+
Object.assign(T, urlToHttpOptions(y = t));
|
|
500
|
+
return _call(o, c);
|
|
322
501
|
}
|
|
323
502
|
}
|
|
324
|
-
var
|
|
325
|
-
|
|
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
|
-
|
|
508
|
+
c(d?.aborted ? d.reason : t);
|
|
330
509
|
}
|
|
331
510
|
};
|
|
332
511
|
d?.addEventListener("abort", destroy);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if ("HEAD" ===
|
|
336
|
-
|
|
337
|
-
} else if (null !=
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
})(
|
|
543
|
+
})(l), destroy);
|
|
365
544
|
}
|
|
366
|
-
|
|
367
|
-
|
|
545
|
+
o(function createResponse(e, t, o) {
|
|
546
|
+
const n = new b(e, t);
|
|
368
547
|
Object.defineProperty(n, "url", {
|
|
369
|
-
value:
|
|
548
|
+
value: o.url
|
|
370
549
|
});
|
|
371
|
-
if ("default" !==
|
|
550
|
+
if ("default" !== o.type) {
|
|
372
551
|
Object.defineProperty(n, "type", {
|
|
373
|
-
value:
|
|
552
|
+
value: o.type
|
|
374
553
|
});
|
|
375
554
|
}
|
|
376
|
-
if (
|
|
555
|
+
if (o.redirected) {
|
|
377
556
|
Object.defineProperty(n, "redirected", {
|
|
378
|
-
value:
|
|
557
|
+
value: o.redirected
|
|
379
558
|
});
|
|
380
559
|
}
|
|
381
560
|
return n;
|
|
382
|
-
}(
|
|
561
|
+
}(i, s, {
|
|
383
562
|
type: "default",
|
|
384
|
-
url:
|
|
385
|
-
redirected:
|
|
563
|
+
url: y.toString(),
|
|
564
|
+
redirected: g > 0
|
|
386
565
|
}));
|
|
387
566
|
}));
|
|
388
|
-
l.on("error",
|
|
389
|
-
if (!
|
|
390
|
-
|
|
567
|
+
l.on("error", c);
|
|
568
|
+
if (!w.has("Accept")) {
|
|
569
|
+
w.set("Accept", "*/*");
|
|
391
570
|
}
|
|
392
|
-
if (
|
|
393
|
-
|
|
571
|
+
if (h.contentType) {
|
|
572
|
+
w.set("Content-Type", h.contentType);
|
|
394
573
|
}
|
|
395
|
-
if (null ==
|
|
396
|
-
|
|
397
|
-
} else if (null !=
|
|
398
|
-
|
|
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 (
|
|
405
|
-
e.setHeader(
|
|
583
|
+
for (const [o, n] of t) {
|
|
584
|
+
e.setHeader(o, n);
|
|
406
585
|
}
|
|
407
586
|
}
|
|
408
|
-
})(l,
|
|
409
|
-
if (null ==
|
|
587
|
+
})(l, w);
|
|
588
|
+
if (null == h.body) {
|
|
410
589
|
l.end();
|
|
411
|
-
} else if (
|
|
412
|
-
l.write(
|
|
590
|
+
} else if (h.body instanceof Uint8Array) {
|
|
591
|
+
l.write(h.body);
|
|
413
592
|
l.end();
|
|
414
593
|
} else {
|
|
415
|
-
|
|
416
|
-
n(
|
|
594
|
+
const t = h.body instanceof s ? h.body : e.fromWeb(h.body);
|
|
595
|
+
n(t, l, (e => {
|
|
417
596
|
if (e) {
|
|
418
|
-
|
|
597
|
+
c(e);
|
|
419
598
|
}
|
|
420
599
|
}));
|
|
421
600
|
}
|
|
422
601
|
}));
|
|
423
602
|
}
|
|
424
603
|
|
|
425
|
-
export { y as Blob, Body,
|
|
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
|