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