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