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.mjs
CHANGED
|
@@ -1,159 +1,177 @@
|
|
|
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 a from "node:url";
|
|
8
8
|
|
|
9
|
-
import { isAnyArrayBuffer as
|
|
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
|
|
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;
|
|
26
|
+
|
|
27
|
+
const h = URLSearchParams;
|
|
28
|
+
|
|
29
|
+
const m = URL;
|
|
30
|
+
|
|
31
|
+
let g;
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
let b;
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
let w;
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
let T;
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
if ("undefined" != typeof Request) {
|
|
40
|
+
g = Request;
|
|
41
|
+
}
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
if ("undefined" != typeof Response) {
|
|
44
|
+
b = Response;
|
|
45
|
+
}
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
if ("undefined" != typeof Headers) {
|
|
48
|
+
w = Headers;
|
|
49
|
+
}
|
|
36
50
|
|
|
37
|
-
|
|
51
|
+
if ("undefined" != typeof FormData) {
|
|
52
|
+
T = FormData;
|
|
53
|
+
}
|
|
38
54
|
|
|
39
|
-
|
|
55
|
+
const L = "\r\n";
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
const _ = "-".repeat(2);
|
|
42
58
|
|
|
43
|
-
|
|
59
|
+
const isReadable = t => e.isReadable(t);
|
|
44
60
|
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
72
|
+
const getFormHeader = (e, t, o) => {
|
|
73
|
+
let n = `${_}${e}${L}`;
|
|
56
74
|
n += `Content-Disposition: form-data; name="${t}"`;
|
|
57
|
-
if (isBlob(
|
|
58
|
-
n += `; filename="${
|
|
59
|
-
n += `Content-Type: ${
|
|
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}${
|
|
79
|
+
return `${n}${L}${L}`;
|
|
62
80
|
};
|
|
63
81
|
|
|
64
|
-
|
|
82
|
+
const getFormFooter = e => `${_}${e}${_}${L}${L}`;
|
|
65
83
|
|
|
66
|
-
|
|
84
|
+
const v = new TextEncoder;
|
|
67
85
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
92
|
+
s = 0;
|
|
75
93
|
} else if ("string" == typeof t) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
n =
|
|
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
|
-
|
|
82
|
-
n =
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
92
|
-
} else if (
|
|
93
|
-
|
|
94
|
-
n =
|
|
95
|
-
|
|
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
|
-
|
|
98
|
-
n =
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for (
|
|
108
|
-
|
|
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
|
|
111
|
-
})(t,
|
|
128
|
+
return o;
|
|
129
|
+
})(t, r);
|
|
112
130
|
n = e.from(async function* generatorOfFormData(e, t) {
|
|
113
|
-
|
|
114
|
-
for (
|
|
115
|
-
if (isBlob(
|
|
116
|
-
yield
|
|
117
|
-
yield*
|
|
118
|
-
yield
|
|
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
|
|
138
|
+
yield o.encode(getFormHeader(t, n, s) + s + L);
|
|
121
139
|
}
|
|
122
140
|
}
|
|
123
|
-
yield
|
|
124
|
-
}(t,
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
n =
|
|
137
|
-
|
|
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:
|
|
141
|
-
contentType:
|
|
158
|
+
contentLength: s,
|
|
159
|
+
contentType: o,
|
|
142
160
|
body: n
|
|
143
161
|
};
|
|
144
162
|
};
|
|
145
163
|
|
|
146
|
-
|
|
164
|
+
const $ = Symbol("kBodyInternals");
|
|
147
165
|
|
|
148
166
|
class Body {
|
|
149
167
|
constructor(e) {
|
|
150
|
-
this[
|
|
168
|
+
this[$] = extractBody(e);
|
|
151
169
|
}
|
|
152
170
|
get body() {
|
|
153
|
-
return this[
|
|
171
|
+
return this[$].body;
|
|
154
172
|
}
|
|
155
173
|
get bodyUsed() {
|
|
156
|
-
|
|
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
|
-
|
|
167
|
-
return
|
|
184
|
+
const {body: e} = this[$];
|
|
185
|
+
return c(e) ? e : new b(this.body).arrayBuffer();
|
|
168
186
|
}
|
|
169
187
|
async formData() {
|
|
170
|
-
|
|
171
|
-
|
|
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 (
|
|
176
|
-
n["Content-Type"] =
|
|
193
|
+
if (o) {
|
|
194
|
+
n["Content-Type"] = o;
|
|
177
195
|
}
|
|
178
|
-
return new
|
|
196
|
+
return new b(e, {
|
|
179
197
|
headers: n
|
|
180
198
|
}).formData();
|
|
181
199
|
}
|
|
182
200
|
async blob() {
|
|
183
|
-
|
|
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
|
-
|
|
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
|
|
215
|
+
class InflateStream extends o {
|
|
198
216
|
constructor(e) {
|
|
199
217
|
super();
|
|
200
218
|
this._opts = e;
|
|
201
219
|
}
|
|
202
|
-
_transform(e, t,
|
|
220
|
+
_transform(e, t, o) {
|
|
203
221
|
if (!this._inflate) {
|
|
204
222
|
if (0 === e.length) {
|
|
205
|
-
|
|
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,
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
|
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(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
})(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
...urlToHttpOptions(
|
|
281
|
-
method: methodToHttpOption(
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
484
|
+
const s = {
|
|
290
485
|
status: e.statusCode,
|
|
291
486
|
statusText: e.statusMessage,
|
|
292
487
|
headers: headersOfRawHeaders(e.rawHeaders)
|
|
293
488
|
};
|
|
294
|
-
if (301 === (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if ("error" ===
|
|
298
|
-
|
|
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" ===
|
|
301
|
-
|
|
302
|
-
} else if ("follow" ===
|
|
303
|
-
if (++
|
|
304
|
-
|
|
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:" !==
|
|
307
|
-
|
|
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 ===
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
} else if (null !=
|
|
315
|
-
|
|
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
|
-
|
|
513
|
+
h = extractBody(f);
|
|
319
514
|
}
|
|
320
|
-
Object.assign(
|
|
321
|
-
return _call(
|
|
515
|
+
Object.assign(T, urlToHttpOptions(y = t));
|
|
516
|
+
return _call(o, a);
|
|
322
517
|
}
|
|
323
518
|
}
|
|
324
|
-
var
|
|
325
|
-
|
|
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
|
-
|
|
524
|
+
a(d?.aborted ? d.reason : t);
|
|
330
525
|
}
|
|
331
526
|
};
|
|
332
527
|
d?.addEventListener("abort", destroy);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if ("HEAD" ===
|
|
336
|
-
|
|
337
|
-
} else if (null !=
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
})(
|
|
559
|
+
})(l), destroy);
|
|
365
560
|
}
|
|
366
|
-
|
|
367
|
-
|
|
561
|
+
o(function createResponse(e, t, o) {
|
|
562
|
+
const n = new b(e, t);
|
|
368
563
|
Object.defineProperty(n, "url", {
|
|
369
|
-
value:
|
|
564
|
+
value: o.url
|
|
370
565
|
});
|
|
371
|
-
if ("default" !==
|
|
566
|
+
if ("default" !== o.type) {
|
|
372
567
|
Object.defineProperty(n, "type", {
|
|
373
|
-
value:
|
|
568
|
+
value: o.type
|
|
374
569
|
});
|
|
375
570
|
}
|
|
376
|
-
if (
|
|
571
|
+
if (o.redirected) {
|
|
377
572
|
Object.defineProperty(n, "redirected", {
|
|
378
|
-
value:
|
|
573
|
+
value: o.redirected
|
|
379
574
|
});
|
|
380
575
|
}
|
|
381
576
|
return n;
|
|
382
|
-
}(
|
|
577
|
+
}(i, s, {
|
|
383
578
|
type: "default",
|
|
384
|
-
url:
|
|
385
|
-
redirected:
|
|
579
|
+
url: y.toString(),
|
|
580
|
+
redirected: g > 0
|
|
386
581
|
}));
|
|
387
582
|
}));
|
|
388
|
-
l.on("error",
|
|
389
|
-
if (!
|
|
390
|
-
|
|
583
|
+
l.on("error", a);
|
|
584
|
+
if (!w.has("Accept")) {
|
|
585
|
+
w.set("Accept", "*/*");
|
|
391
586
|
}
|
|
392
|
-
if (
|
|
393
|
-
|
|
587
|
+
if (h.contentType) {
|
|
588
|
+
w.set("Content-Type", h.contentType);
|
|
394
589
|
}
|
|
395
|
-
if (null ==
|
|
396
|
-
|
|
397
|
-
} else if (null !=
|
|
398
|
-
|
|
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 (
|
|
405
|
-
e.setHeader(
|
|
599
|
+
for (const [o, n] of t) {
|
|
600
|
+
e.setHeader(o, n);
|
|
406
601
|
}
|
|
407
602
|
}
|
|
408
|
-
})(l,
|
|
409
|
-
if (null ==
|
|
603
|
+
})(l, w);
|
|
604
|
+
if (null == h.body) {
|
|
410
605
|
l.end();
|
|
411
|
-
} else if (
|
|
412
|
-
l.write(
|
|
606
|
+
} else if (h.body instanceof Uint8Array) {
|
|
607
|
+
l.write(h.body);
|
|
413
608
|
l.end();
|
|
414
609
|
} else {
|
|
415
|
-
|
|
416
|
-
n(
|
|
610
|
+
const t = h.body instanceof s ? h.body : e.fromWeb(h.body);
|
|
611
|
+
n(t, l, (e => {
|
|
417
612
|
if (e) {
|
|
418
|
-
|
|
613
|
+
a(e);
|
|
419
614
|
}
|
|
420
615
|
}));
|
|
421
616
|
}
|
|
422
617
|
}));
|
|
423
618
|
}
|
|
424
619
|
|
|
425
|
-
export { y as Blob, Body,
|
|
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
|