@tonyclaw/agent-inspector 4.0.8 → 4.0.10
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/.output/backend/nitro.json +1 -1
- package/.output/cli.js +915 -25970
- package/.output/server/_chunks/ssr-renderer.mjs +1 -38
- package/.output/server/_libs/@opentelemetry/semantic-conventions+[...].mjs +1 -2658
- package/.output/server/_libs/agent-base.mjs +2 -234
- package/.output/server/_libs/ajv-formats.mjs +1 -330
- package/.output/server/_libs/ajv.mjs +8 -6080
- package/.output/server/_libs/anthropic-ai__sdk.mjs +19 -6021
- package/.output/server/_libs/atomically.mjs +1 -155
- package/.output/server/_libs/base64-js.mjs +1 -102
- package/.output/server/_libs/bignumber.js.mjs +1 -1353
- package/.output/server/_libs/buffer-equal-constant-time.mjs +1 -38
- package/.output/server/_libs/conf.mjs +1 -635
- package/.output/server/_libs/cookie-es.mjs +1 -44
- package/.output/server/_libs/core-util-is.mjs +1 -75
- package/.output/server/_libs/data-uri-to-buffer.mjs +1 -39
- package/.output/server/_libs/debounce-fn.mjs +1 -69
- package/.output/server/_libs/debug.mjs +5 -547
- package/.output/server/_libs/dot-prop.mjs +1 -265
- package/.output/server/_libs/ecdsa-sig-formatter.mjs +1 -162
- package/.output/server/_libs/env-paths.mjs +1 -57
- package/.output/server/_libs/extend.mjs +1 -94
- package/.output/server/_libs/fast-deep-equal.mjs +1 -38
- package/.output/server/_libs/fast-uri.mjs +1 -812
- package/.output/server/_libs/fetch-blob.mjs +1 -287
- package/.output/server/_libs/formdata-polyfill.mjs +9 -86
- package/.output/server/_libs/gaxios.mjs +5 -926
- package/.output/server/_libs/gcp-metadata.mjs +1 -322
- package/.output/server/_libs/google-auth-library.mjs +16 -6339
- package/.output/server/_libs/google-logging-utils.mjs +1 -385
- package/.output/server/_libs/google__genai.mjs +13 -18034
- package/.output/server/_libs/h3-v2.mjs +2 -287
- package/.output/server/_libs/h3.mjs +2 -408
- package/.output/server/_libs/has-flag.mjs +1 -16
- package/.output/server/_libs/https-proxy-agent.mjs +7 -280
- package/.output/server/_libs/immediate.mjs +1 -74
- package/.output/server/_libs/inherits.mjs +1 -50
- package/.output/server/_libs/isarray.mjs +1 -14
- package/.output/server/_libs/isbot.mjs +1 -20
- package/.output/server/_libs/json-bigint.mjs +8 -413
- package/.output/server/_libs/json-schema-traverse.mjs +1 -91
- package/.output/server/_libs/jszip.mjs +2 -3051
- package/.output/server/_libs/jwa.mjs +3 -233
- package/.output/server/_libs/jws.mjs +1 -298
- package/.output/server/_libs/lie.mjs +1 -273
- package/.output/server/_libs/mariozechner__pi-agent-core.mjs +1 -824
- package/.output/server/_libs/mariozechner__pi-ai.mjs +34 -22887
- package/.output/server/_libs/mimic-function.mjs +2 -47
- package/.output/server/_libs/mistralai__mistralai.mjs +7 -32045
- package/.output/server/_libs/modelcontextprotocol__core.mjs +1 -1121
- package/.output/server/_libs/modelcontextprotocol__server.mjs +13 -13205
- package/.output/server/_libs/ms.mjs +1 -120
- package/.output/server/_libs/node-domexception.mjs +1 -17
- package/.output/server/_libs/node-fetch.mjs +4 -1578
- package/.output/server/_libs/ohash.mjs +1 -1
- package/.output/server/_libs/openai.mjs +23 -6766
- package/.output/server/_libs/opentelemetry__api.mjs +1 -1678
- package/.output/server/_libs/p-retry.mjs +1 -87
- package/.output/server/_libs/pako.mjs +1 -4223
- package/.output/server/_libs/partial-json.mjs +2 -244
- package/.output/server/_libs/process-nextick-args.mjs +1 -48
- package/.output/server/_libs/react-dom.mjs +62 -10778
- package/.output/server/_libs/react.mjs +1 -519
- package/.output/server/_libs/readable-stream.mjs +1 -1518
- package/.output/server/_libs/retry.mjs +1 -236
- package/.output/server/_libs/rou3.mjs +1 -14
- package/.output/server/_libs/safe-buffer.mjs +1 -126
- package/.output/server/_libs/semver.mjs +1 -1938
- package/.output/server/_libs/seroval-plugins.mjs +1 -58
- package/.output/server/_libs/seroval.mjs +3 -1775
- package/.output/server/_libs/setimmediate.mjs +1 -152
- package/.output/server/_libs/srvx.mjs +4 -1390
- package/.output/server/_libs/stubborn-fs.mjs +1 -91
- package/.output/server/_libs/stubborn-utils.mjs +1 -66
- package/.output/server/_libs/supports-color.mjs +1 -108
- package/.output/server/_libs/tanstack__history.mjs +1 -230
- package/.output/server/_libs/tanstack__react-router.mjs +1 -848
- package/.output/server/_libs/tanstack__react-store.mjs +1 -1
- package/.output/server/_libs/tanstack__router-core.mjs +1 -4839
- package/.output/server/_libs/typebox.mjs +3 -6596
- package/.output/server/_libs/ufo.mjs +1 -54
- package/.output/server/_libs/uint8array-extras.mjs +1 -69
- package/.output/server/_libs/util-deprecate.mjs +1 -12
- package/.output/server/_libs/web-streams-polyfill.mjs +1 -4282
- package/.output/server/_libs/when-exit.mjs +1 -53
- package/.output/server/_libs/ws.mjs +7 -3715
- package/.output/server/_libs/zod-to-json-schema.mjs +5 -1207
- package/.output/server/_libs/zod.mjs +59 -9958
- package/.output/server/_ssr/empty-plugin-adapters-C3Q1xu4u.mjs +1 -0
- package/.output/server/_ssr/index.mjs +2 -1512
- package/.output/server/_ssr/publicBasePathContext--TAQS2_5.mjs +1 -0
- package/.output/server/_ssr/router-B3jax4sN.mjs +341 -0
- package/.output/server/_ssr/start-PDVGOqUN.mjs +1 -0
- package/.output/server/_tanstack-start-manifest_v-D7cKwKzM.mjs +1 -0
- package/.output/server/index.mjs +1 -320
- package/.output/ui/assets/{CompareDrawer-DafpfgaT.js → CompareDrawer-D8fg0prL.js} +1 -1
- package/.output/ui/assets/{InspectorPet-Brsmmfzx.js → InspectorPet-BAY7SAee.js} +1 -1
- package/.output/ui/assets/{ProxyViewerContainer-D2pq1fUr.js → ProxyViewerContainer-BPITPKYp.js} +4 -4
- package/.output/ui/assets/{ReplayDialog-D4mXXgT9.js → ReplayDialog-NLGOmBsc.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-Ccnsq12U.js → RequestAnatomy-DBhRhis7.js} +1 -1
- package/.output/ui/assets/{ResponseView-CJv3vB5X.js → ResponseView-DNXX-dzj.js} +1 -1
- package/.output/ui/assets/{StreamingChunkSequence-CEkLnOF6.js → StreamingChunkSequence-CLiT5Xun.js} +1 -1
- package/.output/ui/assets/{_sessionId-C7s68UH3.js → _sessionId-CY0Jj2Xv.js} +1 -1
- package/.output/ui/assets/{_sessionId-DlG-yHoI.js → _sessionId-Cf0So2vy.js} +1 -1
- package/.output/ui/assets/{index-ChZZrVHa.js → index-BIMJaHOR.js} +1 -1
- package/.output/ui/assets/{index-CFqnSirZ.js → index-DLG3AIXx.js} +1 -1
- package/.output/ui/assets/{index-B0NCZQ93.js → index-DTj5ErVh.js} +2 -2
- package/.output/ui/assets/{index-Cqh47jeU.js → index-ujyZ2AyC.js} +1 -1
- package/.output/ui/assets/{json-viewer-DvpI0vbY.js → json-viewer-BwPQ5x7s.js} +1 -1
- package/.output/ui/assets/{jszip.min-5AG8hW2c.js → jszip.min-CDwYiHmS.js} +1 -1
- package/.output/ui/index.html +1 -1
- package/.output/workers/logFinalizer.worker.js +41 -17739
- package/.output/workers/sessionWorkerEntry.js +41 -17735
- package/package.json +7 -7
- package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +0 -6
- package/.output/server/_ssr/publicBasePathContext-IH2ilOfu.mjs +0 -176
- package/.output/server/_ssr/router-BDyF-OMB.mjs +0 -27187
- package/.output/server/_ssr/start-COQu_AgD.mjs +0 -57
- package/.output/server/_tanstack-start-manifest_v-ClTaMkEj.mjs +0 -4
|
@@ -1,1578 +1,4 @@
|
|
|
1
|
-
import http from "node:http";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { Buffer } from "node:buffer";
|
|
6
|
-
import { d as dataUriToBuffer } from "./data-uri-to-buffer.mjs";
|
|
7
|
-
import { types, deprecate, promisify } from "node:util";
|
|
8
|
-
import { B as Blob, F as File } from "./fetch-blob.mjs";
|
|
9
|
-
import { F as FormData, f as formDataToBlob } from "./formdata-polyfill.mjs";
|
|
10
|
-
import { format } from "node:url";
|
|
11
|
-
import { isIP } from "node:net";
|
|
12
|
-
import "node:fs";
|
|
13
|
-
import "node:path";
|
|
14
|
-
import "./node-domexception.mjs";
|
|
15
|
-
import "./web-streams-polyfill.mjs";
|
|
16
|
-
import "./react.mjs";
|
|
17
|
-
class FetchBaseError extends Error {
|
|
18
|
-
constructor(message, type) {
|
|
19
|
-
super(message);
|
|
20
|
-
Error.captureStackTrace(this, this.constructor);
|
|
21
|
-
this.type = type;
|
|
22
|
-
}
|
|
23
|
-
get name() {
|
|
24
|
-
return this.constructor.name;
|
|
25
|
-
}
|
|
26
|
-
get [Symbol.toStringTag]() {
|
|
27
|
-
return this.constructor.name;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
class FetchError extends FetchBaseError {
|
|
31
|
-
/**
|
|
32
|
-
* @param {string} message - Error message for human
|
|
33
|
-
* @param {string} [type] - Error type for machine
|
|
34
|
-
* @param {SystemError} [systemError] - For Node.js system error
|
|
35
|
-
*/
|
|
36
|
-
constructor(message, type, systemError) {
|
|
37
|
-
super(message, type);
|
|
38
|
-
if (systemError) {
|
|
39
|
-
this.code = this.errno = systemError.code;
|
|
40
|
-
this.erroredSysCall = systemError.syscall;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const NAME = Symbol.toStringTag;
|
|
45
|
-
const isURLSearchParameters = (object) => {
|
|
46
|
-
return typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && typeof object.sort === "function" && object[NAME] === "URLSearchParams";
|
|
47
|
-
};
|
|
48
|
-
const isBlob = (object) => {
|
|
49
|
-
return object && typeof object === "object" && typeof object.arrayBuffer === "function" && typeof object.type === "string" && typeof object.stream === "function" && typeof object.constructor === "function" && /^(Blob|File)$/.test(object[NAME]);
|
|
50
|
-
};
|
|
51
|
-
const isAbortSignal = (object) => {
|
|
52
|
-
return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
|
|
53
|
-
};
|
|
54
|
-
const isDomainOrSubdomain = (destination, original) => {
|
|
55
|
-
const orig = new URL(original).hostname;
|
|
56
|
-
const dest = new URL(destination).hostname;
|
|
57
|
-
return orig === dest || orig.endsWith(`.${dest}`);
|
|
58
|
-
};
|
|
59
|
-
const isSameProtocol = (destination, original) => {
|
|
60
|
-
const orig = new URL(original).protocol;
|
|
61
|
-
const dest = new URL(destination).protocol;
|
|
62
|
-
return orig === dest;
|
|
63
|
-
};
|
|
64
|
-
const pipeline = promisify(Stream.pipeline);
|
|
65
|
-
const INTERNALS$2 = /* @__PURE__ */ Symbol("Body internals");
|
|
66
|
-
class Body {
|
|
67
|
-
constructor(body, {
|
|
68
|
-
size = 0
|
|
69
|
-
} = {}) {
|
|
70
|
-
let boundary = null;
|
|
71
|
-
if (body === null) {
|
|
72
|
-
body = null;
|
|
73
|
-
} else if (isURLSearchParameters(body)) {
|
|
74
|
-
body = Buffer.from(body.toString());
|
|
75
|
-
} else if (isBlob(body)) ;
|
|
76
|
-
else if (Buffer.isBuffer(body)) ;
|
|
77
|
-
else if (types.isAnyArrayBuffer(body)) {
|
|
78
|
-
body = Buffer.from(body);
|
|
79
|
-
} else if (ArrayBuffer.isView(body)) {
|
|
80
|
-
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
81
|
-
} else if (body instanceof Stream) ;
|
|
82
|
-
else if (body instanceof FormData) {
|
|
83
|
-
body = formDataToBlob(body);
|
|
84
|
-
boundary = body.type.split("=")[1];
|
|
85
|
-
} else {
|
|
86
|
-
body = Buffer.from(String(body));
|
|
87
|
-
}
|
|
88
|
-
let stream = body;
|
|
89
|
-
if (Buffer.isBuffer(body)) {
|
|
90
|
-
stream = Stream.Readable.from(body);
|
|
91
|
-
} else if (isBlob(body)) {
|
|
92
|
-
stream = Stream.Readable.from(body.stream());
|
|
93
|
-
}
|
|
94
|
-
this[INTERNALS$2] = {
|
|
95
|
-
body,
|
|
96
|
-
stream,
|
|
97
|
-
boundary,
|
|
98
|
-
disturbed: false,
|
|
99
|
-
error: null
|
|
100
|
-
};
|
|
101
|
-
this.size = size;
|
|
102
|
-
if (body instanceof Stream) {
|
|
103
|
-
body.on("error", (error_) => {
|
|
104
|
-
const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
|
|
105
|
-
this[INTERNALS$2].error = error;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
get body() {
|
|
110
|
-
return this[INTERNALS$2].stream;
|
|
111
|
-
}
|
|
112
|
-
get bodyUsed() {
|
|
113
|
-
return this[INTERNALS$2].disturbed;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Decode response as ArrayBuffer
|
|
117
|
-
*
|
|
118
|
-
* @return Promise
|
|
119
|
-
*/
|
|
120
|
-
async arrayBuffer() {
|
|
121
|
-
const { buffer, byteOffset, byteLength } = await consumeBody(this);
|
|
122
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
123
|
-
}
|
|
124
|
-
async formData() {
|
|
125
|
-
const ct = this.headers.get("content-type");
|
|
126
|
-
if (ct.startsWith("application/x-www-form-urlencoded")) {
|
|
127
|
-
const formData = new FormData();
|
|
128
|
-
const parameters = new URLSearchParams(await this.text());
|
|
129
|
-
for (const [name, value] of parameters) {
|
|
130
|
-
formData.append(name, value);
|
|
131
|
-
}
|
|
132
|
-
return formData;
|
|
133
|
-
}
|
|
134
|
-
const { toFormData: toFormData2 } = await Promise.resolve().then(function() {
|
|
135
|
-
return multipartParser;
|
|
136
|
-
});
|
|
137
|
-
return toFormData2(this.body, ct);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Return raw response as Blob
|
|
141
|
-
*
|
|
142
|
-
* @return Promise
|
|
143
|
-
*/
|
|
144
|
-
async blob() {
|
|
145
|
-
const ct = this.headers && this.headers.get("content-type") || this[INTERNALS$2].body && this[INTERNALS$2].body.type || "";
|
|
146
|
-
const buf = await this.arrayBuffer();
|
|
147
|
-
return new Blob([buf], {
|
|
148
|
-
type: ct
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Decode response as json
|
|
153
|
-
*
|
|
154
|
-
* @return Promise
|
|
155
|
-
*/
|
|
156
|
-
async json() {
|
|
157
|
-
const text = await this.text();
|
|
158
|
-
return JSON.parse(text);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Decode response as text
|
|
162
|
-
*
|
|
163
|
-
* @return Promise
|
|
164
|
-
*/
|
|
165
|
-
async text() {
|
|
166
|
-
const buffer = await consumeBody(this);
|
|
167
|
-
return new TextDecoder().decode(buffer);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Decode response as buffer (non-spec api)
|
|
171
|
-
*
|
|
172
|
-
* @return Promise
|
|
173
|
-
*/
|
|
174
|
-
buffer() {
|
|
175
|
-
return consumeBody(this);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
Body.prototype.buffer = deprecate(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
|
|
179
|
-
Object.defineProperties(Body.prototype, {
|
|
180
|
-
body: { enumerable: true },
|
|
181
|
-
bodyUsed: { enumerable: true },
|
|
182
|
-
arrayBuffer: { enumerable: true },
|
|
183
|
-
blob: { enumerable: true },
|
|
184
|
-
json: { enumerable: true },
|
|
185
|
-
text: { enumerable: true },
|
|
186
|
-
data: { get: deprecate(
|
|
187
|
-
() => {
|
|
188
|
-
},
|
|
189
|
-
"data doesn't exist, use json(), text(), arrayBuffer(), or body instead",
|
|
190
|
-
"https://github.com/node-fetch/node-fetch/issues/1000 (response)"
|
|
191
|
-
) }
|
|
192
|
-
});
|
|
193
|
-
async function consumeBody(data) {
|
|
194
|
-
if (data[INTERNALS$2].disturbed) {
|
|
195
|
-
throw new TypeError(`body used already for: ${data.url}`);
|
|
196
|
-
}
|
|
197
|
-
data[INTERNALS$2].disturbed = true;
|
|
198
|
-
if (data[INTERNALS$2].error) {
|
|
199
|
-
throw data[INTERNALS$2].error;
|
|
200
|
-
}
|
|
201
|
-
const { body } = data;
|
|
202
|
-
if (body === null) {
|
|
203
|
-
return Buffer.alloc(0);
|
|
204
|
-
}
|
|
205
|
-
if (!(body instanceof Stream)) {
|
|
206
|
-
return Buffer.alloc(0);
|
|
207
|
-
}
|
|
208
|
-
const accum = [];
|
|
209
|
-
let accumBytes = 0;
|
|
210
|
-
try {
|
|
211
|
-
for await (const chunk of body) {
|
|
212
|
-
if (data.size > 0 && accumBytes + chunk.length > data.size) {
|
|
213
|
-
const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
|
|
214
|
-
body.destroy(error);
|
|
215
|
-
throw error;
|
|
216
|
-
}
|
|
217
|
-
accumBytes += chunk.length;
|
|
218
|
-
accum.push(chunk);
|
|
219
|
-
}
|
|
220
|
-
} catch (error) {
|
|
221
|
-
const error_ = error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
|
|
222
|
-
throw error_;
|
|
223
|
-
}
|
|
224
|
-
if (body.readableEnded === true || body._readableState.ended === true) {
|
|
225
|
-
try {
|
|
226
|
-
if (accum.every((c) => typeof c === "string")) {
|
|
227
|
-
return Buffer.from(accum.join(""));
|
|
228
|
-
}
|
|
229
|
-
return Buffer.concat(accum, accumBytes);
|
|
230
|
-
} catch (error) {
|
|
231
|
-
throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const clone = (instance, highWaterMark) => {
|
|
238
|
-
let p1;
|
|
239
|
-
let p2;
|
|
240
|
-
let { body } = instance[INTERNALS$2];
|
|
241
|
-
if (instance.bodyUsed) {
|
|
242
|
-
throw new Error("cannot clone body after it is used");
|
|
243
|
-
}
|
|
244
|
-
if (body instanceof Stream && typeof body.getBoundary !== "function") {
|
|
245
|
-
p1 = new PassThrough({ highWaterMark });
|
|
246
|
-
p2 = new PassThrough({ highWaterMark });
|
|
247
|
-
body.pipe(p1);
|
|
248
|
-
body.pipe(p2);
|
|
249
|
-
instance[INTERNALS$2].stream = p1;
|
|
250
|
-
body = p2;
|
|
251
|
-
}
|
|
252
|
-
return body;
|
|
253
|
-
};
|
|
254
|
-
const getNonSpecFormDataBoundary = deprecate(
|
|
255
|
-
(body) => body.getBoundary(),
|
|
256
|
-
"form-data doesn't follow the spec and requires special treatment. Use alternative package",
|
|
257
|
-
"https://github.com/node-fetch/node-fetch/issues/1167"
|
|
258
|
-
);
|
|
259
|
-
const extractContentType = (body, request) => {
|
|
260
|
-
if (body === null) {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
if (typeof body === "string") {
|
|
264
|
-
return "text/plain;charset=UTF-8";
|
|
265
|
-
}
|
|
266
|
-
if (isURLSearchParameters(body)) {
|
|
267
|
-
return "application/x-www-form-urlencoded;charset=UTF-8";
|
|
268
|
-
}
|
|
269
|
-
if (isBlob(body)) {
|
|
270
|
-
return body.type || null;
|
|
271
|
-
}
|
|
272
|
-
if (Buffer.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
if (body instanceof FormData) {
|
|
276
|
-
return `multipart/form-data; boundary=${request[INTERNALS$2].boundary}`;
|
|
277
|
-
}
|
|
278
|
-
if (body && typeof body.getBoundary === "function") {
|
|
279
|
-
return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
|
|
280
|
-
}
|
|
281
|
-
if (body instanceof Stream) {
|
|
282
|
-
return null;
|
|
283
|
-
}
|
|
284
|
-
return "text/plain;charset=UTF-8";
|
|
285
|
-
};
|
|
286
|
-
const getTotalBytes = (request) => {
|
|
287
|
-
const { body } = request[INTERNALS$2];
|
|
288
|
-
if (body === null) {
|
|
289
|
-
return 0;
|
|
290
|
-
}
|
|
291
|
-
if (isBlob(body)) {
|
|
292
|
-
return body.size;
|
|
293
|
-
}
|
|
294
|
-
if (Buffer.isBuffer(body)) {
|
|
295
|
-
return body.length;
|
|
296
|
-
}
|
|
297
|
-
if (body && typeof body.getLengthSync === "function") {
|
|
298
|
-
return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
|
|
299
|
-
}
|
|
300
|
-
return null;
|
|
301
|
-
};
|
|
302
|
-
const writeToStream = async (dest, { body }) => {
|
|
303
|
-
if (body === null) {
|
|
304
|
-
dest.end();
|
|
305
|
-
} else {
|
|
306
|
-
await pipeline(body, dest);
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
const validateHeaderName = typeof http.validateHeaderName === "function" ? http.validateHeaderName : (name) => {
|
|
310
|
-
if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
|
|
311
|
-
const error = new TypeError(`Header name must be a valid HTTP token [${name}]`);
|
|
312
|
-
Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
|
|
313
|
-
throw error;
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
const validateHeaderValue = typeof http.validateHeaderValue === "function" ? http.validateHeaderValue : (name, value) => {
|
|
317
|
-
if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
|
|
318
|
-
const error = new TypeError(`Invalid character in header content ["${name}"]`);
|
|
319
|
-
Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
|
|
320
|
-
throw error;
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
class Headers extends URLSearchParams {
|
|
324
|
-
/**
|
|
325
|
-
* Headers class
|
|
326
|
-
*
|
|
327
|
-
* @constructor
|
|
328
|
-
* @param {HeadersInit} [init] - Response headers
|
|
329
|
-
*/
|
|
330
|
-
constructor(init) {
|
|
331
|
-
let result = [];
|
|
332
|
-
if (init instanceof Headers) {
|
|
333
|
-
const raw = init.raw();
|
|
334
|
-
for (const [name, values] of Object.entries(raw)) {
|
|
335
|
-
result.push(...values.map((value) => [name, value]));
|
|
336
|
-
}
|
|
337
|
-
} else if (init == null) ;
|
|
338
|
-
else if (typeof init === "object" && !types.isBoxedPrimitive(init)) {
|
|
339
|
-
const method = init[Symbol.iterator];
|
|
340
|
-
if (method == null) {
|
|
341
|
-
result.push(...Object.entries(init));
|
|
342
|
-
} else {
|
|
343
|
-
if (typeof method !== "function") {
|
|
344
|
-
throw new TypeError("Header pairs must be iterable");
|
|
345
|
-
}
|
|
346
|
-
result = [...init].map((pair) => {
|
|
347
|
-
if (typeof pair !== "object" || types.isBoxedPrimitive(pair)) {
|
|
348
|
-
throw new TypeError("Each header pair must be an iterable object");
|
|
349
|
-
}
|
|
350
|
-
return [...pair];
|
|
351
|
-
}).map((pair) => {
|
|
352
|
-
if (pair.length !== 2) {
|
|
353
|
-
throw new TypeError("Each header pair must be a name/value tuple");
|
|
354
|
-
}
|
|
355
|
-
return [...pair];
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
} else {
|
|
359
|
-
throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
|
|
360
|
-
}
|
|
361
|
-
result = result.length > 0 ? result.map(([name, value]) => {
|
|
362
|
-
validateHeaderName(name);
|
|
363
|
-
validateHeaderValue(name, String(value));
|
|
364
|
-
return [String(name).toLowerCase(), String(value)];
|
|
365
|
-
}) : void 0;
|
|
366
|
-
super(result);
|
|
367
|
-
return new Proxy(this, {
|
|
368
|
-
get(target, p, receiver) {
|
|
369
|
-
switch (p) {
|
|
370
|
-
case "append":
|
|
371
|
-
case "set":
|
|
372
|
-
return (name, value) => {
|
|
373
|
-
validateHeaderName(name);
|
|
374
|
-
validateHeaderValue(name, String(value));
|
|
375
|
-
return URLSearchParams.prototype[p].call(
|
|
376
|
-
target,
|
|
377
|
-
String(name).toLowerCase(),
|
|
378
|
-
String(value)
|
|
379
|
-
);
|
|
380
|
-
};
|
|
381
|
-
case "delete":
|
|
382
|
-
case "has":
|
|
383
|
-
case "getAll":
|
|
384
|
-
return (name) => {
|
|
385
|
-
validateHeaderName(name);
|
|
386
|
-
return URLSearchParams.prototype[p].call(
|
|
387
|
-
target,
|
|
388
|
-
String(name).toLowerCase()
|
|
389
|
-
);
|
|
390
|
-
};
|
|
391
|
-
case "keys":
|
|
392
|
-
return () => {
|
|
393
|
-
target.sort();
|
|
394
|
-
return new Set(URLSearchParams.prototype.keys.call(target)).keys();
|
|
395
|
-
};
|
|
396
|
-
default:
|
|
397
|
-
return Reflect.get(target, p, receiver);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
get [Symbol.toStringTag]() {
|
|
403
|
-
return this.constructor.name;
|
|
404
|
-
}
|
|
405
|
-
toString() {
|
|
406
|
-
return Object.prototype.toString.call(this);
|
|
407
|
-
}
|
|
408
|
-
get(name) {
|
|
409
|
-
const values = this.getAll(name);
|
|
410
|
-
if (values.length === 0) {
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
let value = values.join(", ");
|
|
414
|
-
if (/^content-encoding$/i.test(name)) {
|
|
415
|
-
value = value.toLowerCase();
|
|
416
|
-
}
|
|
417
|
-
return value;
|
|
418
|
-
}
|
|
419
|
-
forEach(callback, thisArg = void 0) {
|
|
420
|
-
for (const name of this.keys()) {
|
|
421
|
-
Reflect.apply(callback, thisArg, [this.get(name), name, this]);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
*values() {
|
|
425
|
-
for (const name of this.keys()) {
|
|
426
|
-
yield this.get(name);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* @type {() => IterableIterator<[string, string]>}
|
|
431
|
-
*/
|
|
432
|
-
*entries() {
|
|
433
|
-
for (const name of this.keys()) {
|
|
434
|
-
yield [name, this.get(name)];
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
[Symbol.iterator]() {
|
|
438
|
-
return this.entries();
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Node-fetch non-spec method
|
|
442
|
-
* returning all headers and their values as array
|
|
443
|
-
* @returns {Record<string, string[]>}
|
|
444
|
-
*/
|
|
445
|
-
raw() {
|
|
446
|
-
return [...this.keys()].reduce((result, key) => {
|
|
447
|
-
result[key] = this.getAll(key);
|
|
448
|
-
return result;
|
|
449
|
-
}, {});
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* For better console.log(headers) and also to convert Headers into Node.js Request compatible format
|
|
453
|
-
*/
|
|
454
|
-
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
455
|
-
return [...this.keys()].reduce((result, key) => {
|
|
456
|
-
const values = this.getAll(key);
|
|
457
|
-
if (key === "host") {
|
|
458
|
-
result[key] = values[0];
|
|
459
|
-
} else {
|
|
460
|
-
result[key] = values.length > 1 ? values : values[0];
|
|
461
|
-
}
|
|
462
|
-
return result;
|
|
463
|
-
}, {});
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
Object.defineProperties(
|
|
467
|
-
Headers.prototype,
|
|
468
|
-
["get", "entries", "forEach", "values"].reduce((result, property) => {
|
|
469
|
-
result[property] = { enumerable: true };
|
|
470
|
-
return result;
|
|
471
|
-
}, {})
|
|
472
|
-
);
|
|
473
|
-
function fromRawHeaders(headers = []) {
|
|
474
|
-
return new Headers(
|
|
475
|
-
headers.reduce((result, value, index, array) => {
|
|
476
|
-
if (index % 2 === 0) {
|
|
477
|
-
result.push(array.slice(index, index + 2));
|
|
478
|
-
}
|
|
479
|
-
return result;
|
|
480
|
-
}, []).filter(([name, value]) => {
|
|
481
|
-
try {
|
|
482
|
-
validateHeaderName(name);
|
|
483
|
-
validateHeaderValue(name, String(value));
|
|
484
|
-
return true;
|
|
485
|
-
} catch {
|
|
486
|
-
return false;
|
|
487
|
-
}
|
|
488
|
-
})
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
const redirectStatus = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
492
|
-
const isRedirect = (code) => {
|
|
493
|
-
return redirectStatus.has(code);
|
|
494
|
-
};
|
|
495
|
-
const INTERNALS$1 = /* @__PURE__ */ Symbol("Response internals");
|
|
496
|
-
class Response extends Body {
|
|
497
|
-
constructor(body = null, options = {}) {
|
|
498
|
-
super(body, options);
|
|
499
|
-
const status = options.status != null ? options.status : 200;
|
|
500
|
-
const headers = new Headers(options.headers);
|
|
501
|
-
if (body !== null && !headers.has("Content-Type")) {
|
|
502
|
-
const contentType = extractContentType(body, this);
|
|
503
|
-
if (contentType) {
|
|
504
|
-
headers.append("Content-Type", contentType);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
this[INTERNALS$1] = {
|
|
508
|
-
type: "default",
|
|
509
|
-
url: options.url,
|
|
510
|
-
status,
|
|
511
|
-
statusText: options.statusText || "",
|
|
512
|
-
headers,
|
|
513
|
-
counter: options.counter,
|
|
514
|
-
highWaterMark: options.highWaterMark
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
get type() {
|
|
518
|
-
return this[INTERNALS$1].type;
|
|
519
|
-
}
|
|
520
|
-
get url() {
|
|
521
|
-
return this[INTERNALS$1].url || "";
|
|
522
|
-
}
|
|
523
|
-
get status() {
|
|
524
|
-
return this[INTERNALS$1].status;
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Convenience property representing if the request ended normally
|
|
528
|
-
*/
|
|
529
|
-
get ok() {
|
|
530
|
-
return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
|
|
531
|
-
}
|
|
532
|
-
get redirected() {
|
|
533
|
-
return this[INTERNALS$1].counter > 0;
|
|
534
|
-
}
|
|
535
|
-
get statusText() {
|
|
536
|
-
return this[INTERNALS$1].statusText;
|
|
537
|
-
}
|
|
538
|
-
get headers() {
|
|
539
|
-
return this[INTERNALS$1].headers;
|
|
540
|
-
}
|
|
541
|
-
get highWaterMark() {
|
|
542
|
-
return this[INTERNALS$1].highWaterMark;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Clone this response
|
|
546
|
-
*
|
|
547
|
-
* @return Response
|
|
548
|
-
*/
|
|
549
|
-
clone() {
|
|
550
|
-
return new Response(clone(this, this.highWaterMark), {
|
|
551
|
-
type: this.type,
|
|
552
|
-
url: this.url,
|
|
553
|
-
status: this.status,
|
|
554
|
-
statusText: this.statusText,
|
|
555
|
-
headers: this.headers,
|
|
556
|
-
ok: this.ok,
|
|
557
|
-
redirected: this.redirected,
|
|
558
|
-
size: this.size,
|
|
559
|
-
highWaterMark: this.highWaterMark
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* @param {string} url The URL that the new response is to originate from.
|
|
564
|
-
* @param {number} status An optional status code for the response (e.g., 302.)
|
|
565
|
-
* @returns {Response} A Response object.
|
|
566
|
-
*/
|
|
567
|
-
static redirect(url, status = 302) {
|
|
568
|
-
if (!isRedirect(status)) {
|
|
569
|
-
throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
|
|
570
|
-
}
|
|
571
|
-
return new Response(null, {
|
|
572
|
-
headers: {
|
|
573
|
-
location: new URL(url).toString()
|
|
574
|
-
},
|
|
575
|
-
status
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
static error() {
|
|
579
|
-
const response = new Response(null, { status: 0, statusText: "" });
|
|
580
|
-
response[INTERNALS$1].type = "error";
|
|
581
|
-
return response;
|
|
582
|
-
}
|
|
583
|
-
static json(data = void 0, init = {}) {
|
|
584
|
-
const body = JSON.stringify(data);
|
|
585
|
-
if (body === void 0) {
|
|
586
|
-
throw new TypeError("data is not JSON serializable");
|
|
587
|
-
}
|
|
588
|
-
const headers = new Headers(init && init.headers);
|
|
589
|
-
if (!headers.has("content-type")) {
|
|
590
|
-
headers.set("content-type", "application/json");
|
|
591
|
-
}
|
|
592
|
-
return new Response(body, {
|
|
593
|
-
...init,
|
|
594
|
-
headers
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
get [Symbol.toStringTag]() {
|
|
598
|
-
return "Response";
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
Object.defineProperties(Response.prototype, {
|
|
602
|
-
type: { enumerable: true },
|
|
603
|
-
url: { enumerable: true },
|
|
604
|
-
status: { enumerable: true },
|
|
605
|
-
ok: { enumerable: true },
|
|
606
|
-
redirected: { enumerable: true },
|
|
607
|
-
statusText: { enumerable: true },
|
|
608
|
-
headers: { enumerable: true },
|
|
609
|
-
clone: { enumerable: true }
|
|
610
|
-
});
|
|
611
|
-
const getSearch = (parsedURL) => {
|
|
612
|
-
if (parsedURL.search) {
|
|
613
|
-
return parsedURL.search;
|
|
614
|
-
}
|
|
615
|
-
const lastOffset = parsedURL.href.length - 1;
|
|
616
|
-
const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
|
|
617
|
-
return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
|
|
618
|
-
};
|
|
619
|
-
function stripURLForUseAsAReferrer(url, originOnly = false) {
|
|
620
|
-
if (url == null) {
|
|
621
|
-
return "no-referrer";
|
|
622
|
-
}
|
|
623
|
-
url = new URL(url);
|
|
624
|
-
if (/^(about|blob|data):$/.test(url.protocol)) {
|
|
625
|
-
return "no-referrer";
|
|
626
|
-
}
|
|
627
|
-
url.username = "";
|
|
628
|
-
url.password = "";
|
|
629
|
-
url.hash = "";
|
|
630
|
-
if (originOnly) {
|
|
631
|
-
url.pathname = "";
|
|
632
|
-
url.search = "";
|
|
633
|
-
}
|
|
634
|
-
return url;
|
|
635
|
-
}
|
|
636
|
-
const ReferrerPolicy = /* @__PURE__ */ new Set([
|
|
637
|
-
"",
|
|
638
|
-
"no-referrer",
|
|
639
|
-
"no-referrer-when-downgrade",
|
|
640
|
-
"same-origin",
|
|
641
|
-
"origin",
|
|
642
|
-
"strict-origin",
|
|
643
|
-
"origin-when-cross-origin",
|
|
644
|
-
"strict-origin-when-cross-origin",
|
|
645
|
-
"unsafe-url"
|
|
646
|
-
]);
|
|
647
|
-
const DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
|
|
648
|
-
function validateReferrerPolicy(referrerPolicy) {
|
|
649
|
-
if (!ReferrerPolicy.has(referrerPolicy)) {
|
|
650
|
-
throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
|
|
651
|
-
}
|
|
652
|
-
return referrerPolicy;
|
|
653
|
-
}
|
|
654
|
-
function isOriginPotentiallyTrustworthy(url) {
|
|
655
|
-
if (/^(http|ws)s:$/.test(url.protocol)) {
|
|
656
|
-
return true;
|
|
657
|
-
}
|
|
658
|
-
const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
|
|
659
|
-
const hostIPVersion = isIP(hostIp);
|
|
660
|
-
if (hostIPVersion === 4 && /^127\./.test(hostIp)) {
|
|
661
|
-
return true;
|
|
662
|
-
}
|
|
663
|
-
if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) {
|
|
664
|
-
return true;
|
|
665
|
-
}
|
|
666
|
-
if (url.host === "localhost" || url.host.endsWith(".localhost")) {
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
if (url.protocol === "file:") {
|
|
670
|
-
return true;
|
|
671
|
-
}
|
|
672
|
-
return false;
|
|
673
|
-
}
|
|
674
|
-
function isUrlPotentiallyTrustworthy(url) {
|
|
675
|
-
if (/^about:(blank|srcdoc)$/.test(url)) {
|
|
676
|
-
return true;
|
|
677
|
-
}
|
|
678
|
-
if (url.protocol === "data:") {
|
|
679
|
-
return true;
|
|
680
|
-
}
|
|
681
|
-
if (/^(blob|filesystem):$/.test(url.protocol)) {
|
|
682
|
-
return true;
|
|
683
|
-
}
|
|
684
|
-
return isOriginPotentiallyTrustworthy(url);
|
|
685
|
-
}
|
|
686
|
-
function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
|
|
687
|
-
if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
|
|
688
|
-
return null;
|
|
689
|
-
}
|
|
690
|
-
const policy = request.referrerPolicy;
|
|
691
|
-
if (request.referrer === "about:client") {
|
|
692
|
-
return "no-referrer";
|
|
693
|
-
}
|
|
694
|
-
const referrerSource = request.referrer;
|
|
695
|
-
let referrerURL = stripURLForUseAsAReferrer(referrerSource);
|
|
696
|
-
let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
|
|
697
|
-
if (referrerURL.toString().length > 4096) {
|
|
698
|
-
referrerURL = referrerOrigin;
|
|
699
|
-
}
|
|
700
|
-
if (referrerURLCallback) {
|
|
701
|
-
referrerURL = referrerURLCallback(referrerURL);
|
|
702
|
-
}
|
|
703
|
-
if (referrerOriginCallback) {
|
|
704
|
-
referrerOrigin = referrerOriginCallback(referrerOrigin);
|
|
705
|
-
}
|
|
706
|
-
const currentURL = new URL(request.url);
|
|
707
|
-
switch (policy) {
|
|
708
|
-
case "no-referrer":
|
|
709
|
-
return "no-referrer";
|
|
710
|
-
case "origin":
|
|
711
|
-
return referrerOrigin;
|
|
712
|
-
case "unsafe-url":
|
|
713
|
-
return referrerURL;
|
|
714
|
-
case "strict-origin":
|
|
715
|
-
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
|
|
716
|
-
return "no-referrer";
|
|
717
|
-
}
|
|
718
|
-
return referrerOrigin.toString();
|
|
719
|
-
case "strict-origin-when-cross-origin":
|
|
720
|
-
if (referrerURL.origin === currentURL.origin) {
|
|
721
|
-
return referrerURL;
|
|
722
|
-
}
|
|
723
|
-
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
|
|
724
|
-
return "no-referrer";
|
|
725
|
-
}
|
|
726
|
-
return referrerOrigin;
|
|
727
|
-
case "same-origin":
|
|
728
|
-
if (referrerURL.origin === currentURL.origin) {
|
|
729
|
-
return referrerURL;
|
|
730
|
-
}
|
|
731
|
-
return "no-referrer";
|
|
732
|
-
case "origin-when-cross-origin":
|
|
733
|
-
if (referrerURL.origin === currentURL.origin) {
|
|
734
|
-
return referrerURL;
|
|
735
|
-
}
|
|
736
|
-
return referrerOrigin;
|
|
737
|
-
case "no-referrer-when-downgrade":
|
|
738
|
-
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
|
|
739
|
-
return "no-referrer";
|
|
740
|
-
}
|
|
741
|
-
return referrerURL;
|
|
742
|
-
default:
|
|
743
|
-
throw new TypeError(`Invalid referrerPolicy: ${policy}`);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
function parseReferrerPolicyFromHeader(headers) {
|
|
747
|
-
const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
|
|
748
|
-
let policy = "";
|
|
749
|
-
for (const token of policyTokens) {
|
|
750
|
-
if (token && ReferrerPolicy.has(token)) {
|
|
751
|
-
policy = token;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
return policy;
|
|
755
|
-
}
|
|
756
|
-
const INTERNALS = /* @__PURE__ */ Symbol("Request internals");
|
|
757
|
-
const isRequest = (object) => {
|
|
758
|
-
return typeof object === "object" && typeof object[INTERNALS] === "object";
|
|
759
|
-
};
|
|
760
|
-
const doBadDataWarn = deprecate(
|
|
761
|
-
() => {
|
|
762
|
-
},
|
|
763
|
-
".data is not a valid RequestInit property, use .body instead",
|
|
764
|
-
"https://github.com/node-fetch/node-fetch/issues/1000 (request)"
|
|
765
|
-
);
|
|
766
|
-
class Request extends Body {
|
|
767
|
-
constructor(input, init = {}) {
|
|
768
|
-
let parsedURL;
|
|
769
|
-
if (isRequest(input)) {
|
|
770
|
-
parsedURL = new URL(input.url);
|
|
771
|
-
} else {
|
|
772
|
-
parsedURL = new URL(input);
|
|
773
|
-
input = {};
|
|
774
|
-
}
|
|
775
|
-
if (parsedURL.username !== "" || parsedURL.password !== "") {
|
|
776
|
-
throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
|
|
777
|
-
}
|
|
778
|
-
let method = init.method || input.method || "GET";
|
|
779
|
-
if (/^(delete|get|head|options|post|put)$/i.test(method)) {
|
|
780
|
-
method = method.toUpperCase();
|
|
781
|
-
}
|
|
782
|
-
if (!isRequest(init) && "data" in init) {
|
|
783
|
-
doBadDataWarn();
|
|
784
|
-
}
|
|
785
|
-
if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
|
|
786
|
-
throw new TypeError("Request with GET/HEAD method cannot have body");
|
|
787
|
-
}
|
|
788
|
-
const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
|
|
789
|
-
super(inputBody, {
|
|
790
|
-
size: init.size || input.size || 0
|
|
791
|
-
});
|
|
792
|
-
const headers = new Headers(init.headers || input.headers || {});
|
|
793
|
-
if (inputBody !== null && !headers.has("Content-Type")) {
|
|
794
|
-
const contentType = extractContentType(inputBody, this);
|
|
795
|
-
if (contentType) {
|
|
796
|
-
headers.set("Content-Type", contentType);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
let signal = isRequest(input) ? input.signal : null;
|
|
800
|
-
if ("signal" in init) {
|
|
801
|
-
signal = init.signal;
|
|
802
|
-
}
|
|
803
|
-
if (signal != null && !isAbortSignal(signal)) {
|
|
804
|
-
throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
|
|
805
|
-
}
|
|
806
|
-
let referrer = init.referrer == null ? input.referrer : init.referrer;
|
|
807
|
-
if (referrer === "") {
|
|
808
|
-
referrer = "no-referrer";
|
|
809
|
-
} else if (referrer) {
|
|
810
|
-
const parsedReferrer = new URL(referrer);
|
|
811
|
-
referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
|
|
812
|
-
} else {
|
|
813
|
-
referrer = void 0;
|
|
814
|
-
}
|
|
815
|
-
this[INTERNALS] = {
|
|
816
|
-
method,
|
|
817
|
-
redirect: init.redirect || input.redirect || "follow",
|
|
818
|
-
headers,
|
|
819
|
-
parsedURL,
|
|
820
|
-
signal,
|
|
821
|
-
referrer
|
|
822
|
-
};
|
|
823
|
-
this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
|
|
824
|
-
this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
|
|
825
|
-
this.counter = init.counter || input.counter || 0;
|
|
826
|
-
this.agent = init.agent || input.agent;
|
|
827
|
-
this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
|
|
828
|
-
this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
|
|
829
|
-
this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
|
|
830
|
-
}
|
|
831
|
-
/** @returns {string} */
|
|
832
|
-
get method() {
|
|
833
|
-
return this[INTERNALS].method;
|
|
834
|
-
}
|
|
835
|
-
/** @returns {string} */
|
|
836
|
-
get url() {
|
|
837
|
-
return format(this[INTERNALS].parsedURL);
|
|
838
|
-
}
|
|
839
|
-
/** @returns {Headers} */
|
|
840
|
-
get headers() {
|
|
841
|
-
return this[INTERNALS].headers;
|
|
842
|
-
}
|
|
843
|
-
get redirect() {
|
|
844
|
-
return this[INTERNALS].redirect;
|
|
845
|
-
}
|
|
846
|
-
/** @returns {AbortSignal} */
|
|
847
|
-
get signal() {
|
|
848
|
-
return this[INTERNALS].signal;
|
|
849
|
-
}
|
|
850
|
-
// https://fetch.spec.whatwg.org/#dom-request-referrer
|
|
851
|
-
get referrer() {
|
|
852
|
-
if (this[INTERNALS].referrer === "no-referrer") {
|
|
853
|
-
return "";
|
|
854
|
-
}
|
|
855
|
-
if (this[INTERNALS].referrer === "client") {
|
|
856
|
-
return "about:client";
|
|
857
|
-
}
|
|
858
|
-
if (this[INTERNALS].referrer) {
|
|
859
|
-
return this[INTERNALS].referrer.toString();
|
|
860
|
-
}
|
|
861
|
-
return void 0;
|
|
862
|
-
}
|
|
863
|
-
get referrerPolicy() {
|
|
864
|
-
return this[INTERNALS].referrerPolicy;
|
|
865
|
-
}
|
|
866
|
-
set referrerPolicy(referrerPolicy) {
|
|
867
|
-
this[INTERNALS].referrerPolicy = validateReferrerPolicy(referrerPolicy);
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Clone this request
|
|
871
|
-
*
|
|
872
|
-
* @return Request
|
|
873
|
-
*/
|
|
874
|
-
clone() {
|
|
875
|
-
return new Request(this);
|
|
876
|
-
}
|
|
877
|
-
get [Symbol.toStringTag]() {
|
|
878
|
-
return "Request";
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
Object.defineProperties(Request.prototype, {
|
|
882
|
-
method: { enumerable: true },
|
|
883
|
-
url: { enumerable: true },
|
|
884
|
-
headers: { enumerable: true },
|
|
885
|
-
redirect: { enumerable: true },
|
|
886
|
-
clone: { enumerable: true },
|
|
887
|
-
signal: { enumerable: true },
|
|
888
|
-
referrer: { enumerable: true },
|
|
889
|
-
referrerPolicy: { enumerable: true }
|
|
890
|
-
});
|
|
891
|
-
const getNodeRequestOptions = (request) => {
|
|
892
|
-
const { parsedURL } = request[INTERNALS];
|
|
893
|
-
const headers = new Headers(request[INTERNALS].headers);
|
|
894
|
-
if (!headers.has("Accept")) {
|
|
895
|
-
headers.set("Accept", "*/*");
|
|
896
|
-
}
|
|
897
|
-
let contentLengthValue = null;
|
|
898
|
-
if (request.body === null && /^(post|put)$/i.test(request.method)) {
|
|
899
|
-
contentLengthValue = "0";
|
|
900
|
-
}
|
|
901
|
-
if (request.body !== null) {
|
|
902
|
-
const totalBytes = getTotalBytes(request);
|
|
903
|
-
if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
|
|
904
|
-
contentLengthValue = String(totalBytes);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
if (contentLengthValue) {
|
|
908
|
-
headers.set("Content-Length", contentLengthValue);
|
|
909
|
-
}
|
|
910
|
-
if (request.referrerPolicy === "") {
|
|
911
|
-
request.referrerPolicy = DEFAULT_REFERRER_POLICY;
|
|
912
|
-
}
|
|
913
|
-
if (request.referrer && request.referrer !== "no-referrer") {
|
|
914
|
-
request[INTERNALS].referrer = determineRequestsReferrer(request);
|
|
915
|
-
} else {
|
|
916
|
-
request[INTERNALS].referrer = "no-referrer";
|
|
917
|
-
}
|
|
918
|
-
if (request[INTERNALS].referrer instanceof URL) {
|
|
919
|
-
headers.set("Referer", request.referrer);
|
|
920
|
-
}
|
|
921
|
-
if (!headers.has("User-Agent")) {
|
|
922
|
-
headers.set("User-Agent", "node-fetch");
|
|
923
|
-
}
|
|
924
|
-
if (request.compress && !headers.has("Accept-Encoding")) {
|
|
925
|
-
headers.set("Accept-Encoding", "gzip, deflate, br");
|
|
926
|
-
}
|
|
927
|
-
let { agent } = request;
|
|
928
|
-
if (typeof agent === "function") {
|
|
929
|
-
agent = agent(parsedURL);
|
|
930
|
-
}
|
|
931
|
-
const search = getSearch(parsedURL);
|
|
932
|
-
const options = {
|
|
933
|
-
// Overwrite search to retain trailing ? (issue #776)
|
|
934
|
-
path: parsedURL.pathname + search,
|
|
935
|
-
// The following options are not expressed in the URL
|
|
936
|
-
method: request.method,
|
|
937
|
-
headers: headers[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")](),
|
|
938
|
-
insecureHTTPParser: request.insecureHTTPParser,
|
|
939
|
-
agent
|
|
940
|
-
};
|
|
941
|
-
return {
|
|
942
|
-
/** @type {URL} */
|
|
943
|
-
parsedURL,
|
|
944
|
-
options
|
|
945
|
-
};
|
|
946
|
-
};
|
|
947
|
-
class AbortError extends FetchBaseError {
|
|
948
|
-
constructor(message, type = "aborted") {
|
|
949
|
-
super(message, type);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
const supportedSchemas = /* @__PURE__ */ new Set(["data:", "http:", "https:"]);
|
|
953
|
-
async function fetch(url, options_) {
|
|
954
|
-
return new Promise((resolve, reject) => {
|
|
955
|
-
const request = new Request(url, options_);
|
|
956
|
-
const { parsedURL, options } = getNodeRequestOptions(request);
|
|
957
|
-
if (!supportedSchemas.has(parsedURL.protocol)) {
|
|
958
|
-
throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
|
|
959
|
-
}
|
|
960
|
-
if (parsedURL.protocol === "data:") {
|
|
961
|
-
const data = dataUriToBuffer(request.url);
|
|
962
|
-
const response2 = new Response(data, { headers: { "Content-Type": data.typeFull } });
|
|
963
|
-
resolve(response2);
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
|
-
const send = (parsedURL.protocol === "https:" ? nodeHTTPS : http).request;
|
|
967
|
-
const { signal } = request;
|
|
968
|
-
let response = null;
|
|
969
|
-
const abort = () => {
|
|
970
|
-
const error = new AbortError("The operation was aborted.");
|
|
971
|
-
reject(error);
|
|
972
|
-
if (request.body && request.body instanceof Stream.Readable) {
|
|
973
|
-
request.body.destroy(error);
|
|
974
|
-
}
|
|
975
|
-
if (!response || !response.body) {
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
|
-
response.body.emit("error", error);
|
|
979
|
-
};
|
|
980
|
-
if (signal && signal.aborted) {
|
|
981
|
-
abort();
|
|
982
|
-
return;
|
|
983
|
-
}
|
|
984
|
-
const abortAndFinalize = () => {
|
|
985
|
-
abort();
|
|
986
|
-
finalize();
|
|
987
|
-
};
|
|
988
|
-
const request_ = send(parsedURL.toString(), options);
|
|
989
|
-
if (signal) {
|
|
990
|
-
signal.addEventListener("abort", abortAndFinalize);
|
|
991
|
-
}
|
|
992
|
-
const finalize = () => {
|
|
993
|
-
request_.abort();
|
|
994
|
-
if (signal) {
|
|
995
|
-
signal.removeEventListener("abort", abortAndFinalize);
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
request_.on("error", (error) => {
|
|
999
|
-
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
|
|
1000
|
-
finalize();
|
|
1001
|
-
});
|
|
1002
|
-
fixResponseChunkedTransferBadEnding(request_, (error) => {
|
|
1003
|
-
if (response && response.body) {
|
|
1004
|
-
response.body.destroy(error);
|
|
1005
|
-
}
|
|
1006
|
-
});
|
|
1007
|
-
if (process.version < "v14") {
|
|
1008
|
-
request_.on("socket", (s2) => {
|
|
1009
|
-
let endedWithEventsCount;
|
|
1010
|
-
s2.prependListener("end", () => {
|
|
1011
|
-
endedWithEventsCount = s2._eventsCount;
|
|
1012
|
-
});
|
|
1013
|
-
s2.prependListener("close", (hadError) => {
|
|
1014
|
-
if (response && endedWithEventsCount < s2._eventsCount && !hadError) {
|
|
1015
|
-
const error = new Error("Premature close");
|
|
1016
|
-
error.code = "ERR_STREAM_PREMATURE_CLOSE";
|
|
1017
|
-
response.body.emit("error", error);
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
request_.on("response", (response_) => {
|
|
1023
|
-
request_.setTimeout(0);
|
|
1024
|
-
const headers = fromRawHeaders(response_.rawHeaders);
|
|
1025
|
-
if (isRedirect(response_.statusCode)) {
|
|
1026
|
-
const location = headers.get("Location");
|
|
1027
|
-
let locationURL = null;
|
|
1028
|
-
try {
|
|
1029
|
-
locationURL = location === null ? null : new URL(location, request.url);
|
|
1030
|
-
} catch {
|
|
1031
|
-
if (request.redirect !== "manual") {
|
|
1032
|
-
reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
|
|
1033
|
-
finalize();
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
switch (request.redirect) {
|
|
1038
|
-
case "error":
|
|
1039
|
-
reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
|
|
1040
|
-
finalize();
|
|
1041
|
-
return;
|
|
1042
|
-
case "manual":
|
|
1043
|
-
break;
|
|
1044
|
-
case "follow": {
|
|
1045
|
-
if (locationURL === null) {
|
|
1046
|
-
break;
|
|
1047
|
-
}
|
|
1048
|
-
if (request.counter >= request.follow) {
|
|
1049
|
-
reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
|
|
1050
|
-
finalize();
|
|
1051
|
-
return;
|
|
1052
|
-
}
|
|
1053
|
-
const requestOptions = {
|
|
1054
|
-
headers: new Headers(request.headers),
|
|
1055
|
-
follow: request.follow,
|
|
1056
|
-
counter: request.counter + 1,
|
|
1057
|
-
agent: request.agent,
|
|
1058
|
-
compress: request.compress,
|
|
1059
|
-
method: request.method,
|
|
1060
|
-
body: clone(request),
|
|
1061
|
-
signal: request.signal,
|
|
1062
|
-
size: request.size,
|
|
1063
|
-
referrer: request.referrer,
|
|
1064
|
-
referrerPolicy: request.referrerPolicy
|
|
1065
|
-
};
|
|
1066
|
-
if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {
|
|
1067
|
-
for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
|
|
1068
|
-
requestOptions.headers.delete(name);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
if (response_.statusCode !== 303 && request.body && options_.body instanceof Stream.Readable) {
|
|
1072
|
-
reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
|
|
1073
|
-
finalize();
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
|
|
1077
|
-
requestOptions.method = "GET";
|
|
1078
|
-
requestOptions.body = void 0;
|
|
1079
|
-
requestOptions.headers.delete("content-length");
|
|
1080
|
-
}
|
|
1081
|
-
const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
|
|
1082
|
-
if (responseReferrerPolicy) {
|
|
1083
|
-
requestOptions.referrerPolicy = responseReferrerPolicy;
|
|
1084
|
-
}
|
|
1085
|
-
resolve(fetch(new Request(locationURL, requestOptions)));
|
|
1086
|
-
finalize();
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
default:
|
|
1090
|
-
return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
if (signal) {
|
|
1094
|
-
response_.once("end", () => {
|
|
1095
|
-
signal.removeEventListener("abort", abortAndFinalize);
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
let body = pipeline$1(response_, new PassThrough(), (error) => {
|
|
1099
|
-
if (error) {
|
|
1100
|
-
reject(error);
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
if (process.version < "v12.10") {
|
|
1104
|
-
response_.on("aborted", abortAndFinalize);
|
|
1105
|
-
}
|
|
1106
|
-
const responseOptions = {
|
|
1107
|
-
url: request.url,
|
|
1108
|
-
status: response_.statusCode,
|
|
1109
|
-
statusText: response_.statusMessage,
|
|
1110
|
-
headers,
|
|
1111
|
-
size: request.size,
|
|
1112
|
-
counter: request.counter,
|
|
1113
|
-
highWaterMark: request.highWaterMark
|
|
1114
|
-
};
|
|
1115
|
-
const codings = headers.get("Content-Encoding");
|
|
1116
|
-
if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
|
|
1117
|
-
response = new Response(body, responseOptions);
|
|
1118
|
-
resolve(response);
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
const zlibOptions = {
|
|
1122
|
-
flush: zlib.Z_SYNC_FLUSH,
|
|
1123
|
-
finishFlush: zlib.Z_SYNC_FLUSH
|
|
1124
|
-
};
|
|
1125
|
-
if (codings === "gzip" || codings === "x-gzip") {
|
|
1126
|
-
body = pipeline$1(body, zlib.createGunzip(zlibOptions), (error) => {
|
|
1127
|
-
if (error) {
|
|
1128
|
-
reject(error);
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
response = new Response(body, responseOptions);
|
|
1132
|
-
resolve(response);
|
|
1133
|
-
return;
|
|
1134
|
-
}
|
|
1135
|
-
if (codings === "deflate" || codings === "x-deflate") {
|
|
1136
|
-
const raw = pipeline$1(response_, new PassThrough(), (error) => {
|
|
1137
|
-
if (error) {
|
|
1138
|
-
reject(error);
|
|
1139
|
-
}
|
|
1140
|
-
});
|
|
1141
|
-
raw.once("data", (chunk) => {
|
|
1142
|
-
if ((chunk[0] & 15) === 8) {
|
|
1143
|
-
body = pipeline$1(body, zlib.createInflate(), (error) => {
|
|
1144
|
-
if (error) {
|
|
1145
|
-
reject(error);
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
|
-
} else {
|
|
1149
|
-
body = pipeline$1(body, zlib.createInflateRaw(), (error) => {
|
|
1150
|
-
if (error) {
|
|
1151
|
-
reject(error);
|
|
1152
|
-
}
|
|
1153
|
-
});
|
|
1154
|
-
}
|
|
1155
|
-
response = new Response(body, responseOptions);
|
|
1156
|
-
resolve(response);
|
|
1157
|
-
});
|
|
1158
|
-
raw.once("end", () => {
|
|
1159
|
-
if (!response) {
|
|
1160
|
-
response = new Response(body, responseOptions);
|
|
1161
|
-
resolve(response);
|
|
1162
|
-
}
|
|
1163
|
-
});
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
if (codings === "br") {
|
|
1167
|
-
body = pipeline$1(body, zlib.createBrotliDecompress(), (error) => {
|
|
1168
|
-
if (error) {
|
|
1169
|
-
reject(error);
|
|
1170
|
-
}
|
|
1171
|
-
});
|
|
1172
|
-
response = new Response(body, responseOptions);
|
|
1173
|
-
resolve(response);
|
|
1174
|
-
return;
|
|
1175
|
-
}
|
|
1176
|
-
response = new Response(body, responseOptions);
|
|
1177
|
-
resolve(response);
|
|
1178
|
-
});
|
|
1179
|
-
writeToStream(request_, request).catch(reject);
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
|
-
function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
1183
|
-
const LAST_CHUNK = Buffer.from("0\r\n\r\n");
|
|
1184
|
-
let isChunkedTransfer = false;
|
|
1185
|
-
let properLastChunkReceived = false;
|
|
1186
|
-
let previousChunk;
|
|
1187
|
-
request.on("response", (response) => {
|
|
1188
|
-
const { headers } = response;
|
|
1189
|
-
isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
|
|
1190
|
-
});
|
|
1191
|
-
request.on("socket", (socket) => {
|
|
1192
|
-
const onSocketClose = () => {
|
|
1193
|
-
if (isChunkedTransfer && !properLastChunkReceived) {
|
|
1194
|
-
const error = new Error("Premature close");
|
|
1195
|
-
error.code = "ERR_STREAM_PREMATURE_CLOSE";
|
|
1196
|
-
errorCallback(error);
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1199
|
-
const onData = (buf) => {
|
|
1200
|
-
properLastChunkReceived = Buffer.compare(buf.slice(-5), LAST_CHUNK) === 0;
|
|
1201
|
-
if (!properLastChunkReceived && previousChunk) {
|
|
1202
|
-
properLastChunkReceived = Buffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && Buffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
|
|
1203
|
-
}
|
|
1204
|
-
previousChunk = buf;
|
|
1205
|
-
};
|
|
1206
|
-
socket.prependListener("close", onSocketClose);
|
|
1207
|
-
socket.on("data", onData);
|
|
1208
|
-
request.on("close", () => {
|
|
1209
|
-
socket.removeListener("close", onSocketClose);
|
|
1210
|
-
socket.removeListener("data", onData);
|
|
1211
|
-
});
|
|
1212
|
-
});
|
|
1213
|
-
}
|
|
1214
|
-
let s = 0;
|
|
1215
|
-
const S = {
|
|
1216
|
-
START_BOUNDARY: s++,
|
|
1217
|
-
HEADER_FIELD_START: s++,
|
|
1218
|
-
HEADER_FIELD: s++,
|
|
1219
|
-
HEADER_VALUE_START: s++,
|
|
1220
|
-
HEADER_VALUE: s++,
|
|
1221
|
-
HEADER_VALUE_ALMOST_DONE: s++,
|
|
1222
|
-
HEADERS_ALMOST_DONE: s++,
|
|
1223
|
-
PART_DATA_START: s++,
|
|
1224
|
-
PART_DATA: s++,
|
|
1225
|
-
END: s++
|
|
1226
|
-
};
|
|
1227
|
-
let f = 1;
|
|
1228
|
-
const F = {
|
|
1229
|
-
PART_BOUNDARY: f,
|
|
1230
|
-
LAST_BOUNDARY: f *= 2
|
|
1231
|
-
};
|
|
1232
|
-
const LF = 10;
|
|
1233
|
-
const CR = 13;
|
|
1234
|
-
const SPACE = 32;
|
|
1235
|
-
const HYPHEN = 45;
|
|
1236
|
-
const COLON = 58;
|
|
1237
|
-
const A = 97;
|
|
1238
|
-
const Z = 122;
|
|
1239
|
-
const lower = (c) => c | 32;
|
|
1240
|
-
const noop = () => {
|
|
1241
|
-
};
|
|
1242
|
-
class MultipartParser {
|
|
1243
|
-
/**
|
|
1244
|
-
* @param {string} boundary
|
|
1245
|
-
*/
|
|
1246
|
-
constructor(boundary) {
|
|
1247
|
-
this.index = 0;
|
|
1248
|
-
this.flags = 0;
|
|
1249
|
-
this.onHeaderEnd = noop;
|
|
1250
|
-
this.onHeaderField = noop;
|
|
1251
|
-
this.onHeadersEnd = noop;
|
|
1252
|
-
this.onHeaderValue = noop;
|
|
1253
|
-
this.onPartBegin = noop;
|
|
1254
|
-
this.onPartData = noop;
|
|
1255
|
-
this.onPartEnd = noop;
|
|
1256
|
-
this.boundaryChars = {};
|
|
1257
|
-
boundary = "\r\n--" + boundary;
|
|
1258
|
-
const ui8a = new Uint8Array(boundary.length);
|
|
1259
|
-
for (let i = 0; i < boundary.length; i++) {
|
|
1260
|
-
ui8a[i] = boundary.charCodeAt(i);
|
|
1261
|
-
this.boundaryChars[ui8a[i]] = true;
|
|
1262
|
-
}
|
|
1263
|
-
this.boundary = ui8a;
|
|
1264
|
-
this.lookbehind = new Uint8Array(this.boundary.length + 8);
|
|
1265
|
-
this.state = S.START_BOUNDARY;
|
|
1266
|
-
}
|
|
1267
|
-
/**
|
|
1268
|
-
* @param {Uint8Array} data
|
|
1269
|
-
*/
|
|
1270
|
-
write(data) {
|
|
1271
|
-
let i = 0;
|
|
1272
|
-
const length_ = data.length;
|
|
1273
|
-
let previousIndex = this.index;
|
|
1274
|
-
let { lookbehind, boundary, boundaryChars, index, state, flags } = this;
|
|
1275
|
-
const boundaryLength = this.boundary.length;
|
|
1276
|
-
const boundaryEnd = boundaryLength - 1;
|
|
1277
|
-
const bufferLength = data.length;
|
|
1278
|
-
let c;
|
|
1279
|
-
let cl;
|
|
1280
|
-
const mark = (name) => {
|
|
1281
|
-
this[name + "Mark"] = i;
|
|
1282
|
-
};
|
|
1283
|
-
const clear = (name) => {
|
|
1284
|
-
delete this[name + "Mark"];
|
|
1285
|
-
};
|
|
1286
|
-
const callback = (callbackSymbol, start, end, ui8a) => {
|
|
1287
|
-
if (start === void 0 || start !== end) {
|
|
1288
|
-
this[callbackSymbol](ui8a && ui8a.subarray(start, end));
|
|
1289
|
-
}
|
|
1290
|
-
};
|
|
1291
|
-
const dataCallback = (name, clear2) => {
|
|
1292
|
-
const markSymbol = name + "Mark";
|
|
1293
|
-
if (!(markSymbol in this)) {
|
|
1294
|
-
return;
|
|
1295
|
-
}
|
|
1296
|
-
if (clear2) {
|
|
1297
|
-
callback(name, this[markSymbol], i, data);
|
|
1298
|
-
delete this[markSymbol];
|
|
1299
|
-
} else {
|
|
1300
|
-
callback(name, this[markSymbol], data.length, data);
|
|
1301
|
-
this[markSymbol] = 0;
|
|
1302
|
-
}
|
|
1303
|
-
};
|
|
1304
|
-
for (i = 0; i < length_; i++) {
|
|
1305
|
-
c = data[i];
|
|
1306
|
-
switch (state) {
|
|
1307
|
-
case S.START_BOUNDARY:
|
|
1308
|
-
if (index === boundary.length - 2) {
|
|
1309
|
-
if (c === HYPHEN) {
|
|
1310
|
-
flags |= F.LAST_BOUNDARY;
|
|
1311
|
-
} else if (c !== CR) {
|
|
1312
|
-
return;
|
|
1313
|
-
}
|
|
1314
|
-
index++;
|
|
1315
|
-
break;
|
|
1316
|
-
} else if (index - 1 === boundary.length - 2) {
|
|
1317
|
-
if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
|
|
1318
|
-
state = S.END;
|
|
1319
|
-
flags = 0;
|
|
1320
|
-
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
|
|
1321
|
-
index = 0;
|
|
1322
|
-
callback("onPartBegin");
|
|
1323
|
-
state = S.HEADER_FIELD_START;
|
|
1324
|
-
} else {
|
|
1325
|
-
return;
|
|
1326
|
-
}
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
if (c !== boundary[index + 2]) {
|
|
1330
|
-
index = -2;
|
|
1331
|
-
}
|
|
1332
|
-
if (c === boundary[index + 2]) {
|
|
1333
|
-
index++;
|
|
1334
|
-
}
|
|
1335
|
-
break;
|
|
1336
|
-
case S.HEADER_FIELD_START:
|
|
1337
|
-
state = S.HEADER_FIELD;
|
|
1338
|
-
mark("onHeaderField");
|
|
1339
|
-
index = 0;
|
|
1340
|
-
// falls through
|
|
1341
|
-
case S.HEADER_FIELD:
|
|
1342
|
-
if (c === CR) {
|
|
1343
|
-
clear("onHeaderField");
|
|
1344
|
-
state = S.HEADERS_ALMOST_DONE;
|
|
1345
|
-
break;
|
|
1346
|
-
}
|
|
1347
|
-
index++;
|
|
1348
|
-
if (c === HYPHEN) {
|
|
1349
|
-
break;
|
|
1350
|
-
}
|
|
1351
|
-
if (c === COLON) {
|
|
1352
|
-
if (index === 1) {
|
|
1353
|
-
return;
|
|
1354
|
-
}
|
|
1355
|
-
dataCallback("onHeaderField", true);
|
|
1356
|
-
state = S.HEADER_VALUE_START;
|
|
1357
|
-
break;
|
|
1358
|
-
}
|
|
1359
|
-
cl = lower(c);
|
|
1360
|
-
if (cl < A || cl > Z) {
|
|
1361
|
-
return;
|
|
1362
|
-
}
|
|
1363
|
-
break;
|
|
1364
|
-
case S.HEADER_VALUE_START:
|
|
1365
|
-
if (c === SPACE) {
|
|
1366
|
-
break;
|
|
1367
|
-
}
|
|
1368
|
-
mark("onHeaderValue");
|
|
1369
|
-
state = S.HEADER_VALUE;
|
|
1370
|
-
// falls through
|
|
1371
|
-
case S.HEADER_VALUE:
|
|
1372
|
-
if (c === CR) {
|
|
1373
|
-
dataCallback("onHeaderValue", true);
|
|
1374
|
-
callback("onHeaderEnd");
|
|
1375
|
-
state = S.HEADER_VALUE_ALMOST_DONE;
|
|
1376
|
-
}
|
|
1377
|
-
break;
|
|
1378
|
-
case S.HEADER_VALUE_ALMOST_DONE:
|
|
1379
|
-
if (c !== LF) {
|
|
1380
|
-
return;
|
|
1381
|
-
}
|
|
1382
|
-
state = S.HEADER_FIELD_START;
|
|
1383
|
-
break;
|
|
1384
|
-
case S.HEADERS_ALMOST_DONE:
|
|
1385
|
-
if (c !== LF) {
|
|
1386
|
-
return;
|
|
1387
|
-
}
|
|
1388
|
-
callback("onHeadersEnd");
|
|
1389
|
-
state = S.PART_DATA_START;
|
|
1390
|
-
break;
|
|
1391
|
-
case S.PART_DATA_START:
|
|
1392
|
-
state = S.PART_DATA;
|
|
1393
|
-
mark("onPartData");
|
|
1394
|
-
// falls through
|
|
1395
|
-
case S.PART_DATA:
|
|
1396
|
-
previousIndex = index;
|
|
1397
|
-
if (index === 0) {
|
|
1398
|
-
i += boundaryEnd;
|
|
1399
|
-
while (i < bufferLength && !(data[i] in boundaryChars)) {
|
|
1400
|
-
i += boundaryLength;
|
|
1401
|
-
}
|
|
1402
|
-
i -= boundaryEnd;
|
|
1403
|
-
c = data[i];
|
|
1404
|
-
}
|
|
1405
|
-
if (index < boundary.length) {
|
|
1406
|
-
if (boundary[index] === c) {
|
|
1407
|
-
if (index === 0) {
|
|
1408
|
-
dataCallback("onPartData", true);
|
|
1409
|
-
}
|
|
1410
|
-
index++;
|
|
1411
|
-
} else {
|
|
1412
|
-
index = 0;
|
|
1413
|
-
}
|
|
1414
|
-
} else if (index === boundary.length) {
|
|
1415
|
-
index++;
|
|
1416
|
-
if (c === CR) {
|
|
1417
|
-
flags |= F.PART_BOUNDARY;
|
|
1418
|
-
} else if (c === HYPHEN) {
|
|
1419
|
-
flags |= F.LAST_BOUNDARY;
|
|
1420
|
-
} else {
|
|
1421
|
-
index = 0;
|
|
1422
|
-
}
|
|
1423
|
-
} else if (index - 1 === boundary.length) {
|
|
1424
|
-
if (flags & F.PART_BOUNDARY) {
|
|
1425
|
-
index = 0;
|
|
1426
|
-
if (c === LF) {
|
|
1427
|
-
flags &= ~F.PART_BOUNDARY;
|
|
1428
|
-
callback("onPartEnd");
|
|
1429
|
-
callback("onPartBegin");
|
|
1430
|
-
state = S.HEADER_FIELD_START;
|
|
1431
|
-
break;
|
|
1432
|
-
}
|
|
1433
|
-
} else if (flags & F.LAST_BOUNDARY) {
|
|
1434
|
-
if (c === HYPHEN) {
|
|
1435
|
-
callback("onPartEnd");
|
|
1436
|
-
state = S.END;
|
|
1437
|
-
flags = 0;
|
|
1438
|
-
} else {
|
|
1439
|
-
index = 0;
|
|
1440
|
-
}
|
|
1441
|
-
} else {
|
|
1442
|
-
index = 0;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
if (index > 0) {
|
|
1446
|
-
lookbehind[index - 1] = c;
|
|
1447
|
-
} else if (previousIndex > 0) {
|
|
1448
|
-
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
|
|
1449
|
-
callback("onPartData", 0, previousIndex, _lookbehind);
|
|
1450
|
-
previousIndex = 0;
|
|
1451
|
-
mark("onPartData");
|
|
1452
|
-
i--;
|
|
1453
|
-
}
|
|
1454
|
-
break;
|
|
1455
|
-
case S.END:
|
|
1456
|
-
break;
|
|
1457
|
-
default:
|
|
1458
|
-
throw new Error(`Unexpected state entered: ${state}`);
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
dataCallback("onHeaderField");
|
|
1462
|
-
dataCallback("onHeaderValue");
|
|
1463
|
-
dataCallback("onPartData");
|
|
1464
|
-
this.index = index;
|
|
1465
|
-
this.state = state;
|
|
1466
|
-
this.flags = flags;
|
|
1467
|
-
}
|
|
1468
|
-
end() {
|
|
1469
|
-
if (this.state === S.HEADER_FIELD_START && this.index === 0 || this.state === S.PART_DATA && this.index === this.boundary.length) {
|
|
1470
|
-
this.onPartEnd();
|
|
1471
|
-
} else if (this.state !== S.END) {
|
|
1472
|
-
throw new Error("MultipartParser.end(): stream ended unexpectedly");
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
function _fileName(headerValue) {
|
|
1477
|
-
const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
|
|
1478
|
-
if (!m) {
|
|
1479
|
-
return;
|
|
1480
|
-
}
|
|
1481
|
-
const match = m[2] || m[3] || "";
|
|
1482
|
-
let filename = match.slice(match.lastIndexOf("\\") + 1);
|
|
1483
|
-
filename = filename.replace(/%22/g, '"');
|
|
1484
|
-
filename = filename.replace(/&#(\d{4});/g, (m2, code) => {
|
|
1485
|
-
return String.fromCharCode(code);
|
|
1486
|
-
});
|
|
1487
|
-
return filename;
|
|
1488
|
-
}
|
|
1489
|
-
async function toFormData(Body2, ct) {
|
|
1490
|
-
if (!/multipart/i.test(ct)) {
|
|
1491
|
-
throw new TypeError("Failed to fetch");
|
|
1492
|
-
}
|
|
1493
|
-
const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
1494
|
-
if (!m) {
|
|
1495
|
-
throw new TypeError("no or bad content-type header, no multipart boundary");
|
|
1496
|
-
}
|
|
1497
|
-
const parser = new MultipartParser(m[1] || m[2]);
|
|
1498
|
-
let headerField;
|
|
1499
|
-
let headerValue;
|
|
1500
|
-
let entryValue;
|
|
1501
|
-
let entryName;
|
|
1502
|
-
let contentType;
|
|
1503
|
-
let filename;
|
|
1504
|
-
const entryChunks = [];
|
|
1505
|
-
const formData = new FormData();
|
|
1506
|
-
const onPartData = (ui8a) => {
|
|
1507
|
-
entryValue += decoder.decode(ui8a, { stream: true });
|
|
1508
|
-
};
|
|
1509
|
-
const appendToFile = (ui8a) => {
|
|
1510
|
-
entryChunks.push(ui8a);
|
|
1511
|
-
};
|
|
1512
|
-
const appendFileToFormData = () => {
|
|
1513
|
-
const file = new File(entryChunks, filename, { type: contentType });
|
|
1514
|
-
formData.append(entryName, file);
|
|
1515
|
-
};
|
|
1516
|
-
const appendEntryToFormData = () => {
|
|
1517
|
-
formData.append(entryName, entryValue);
|
|
1518
|
-
};
|
|
1519
|
-
const decoder = new TextDecoder("utf-8");
|
|
1520
|
-
decoder.decode();
|
|
1521
|
-
parser.onPartBegin = function() {
|
|
1522
|
-
parser.onPartData = onPartData;
|
|
1523
|
-
parser.onPartEnd = appendEntryToFormData;
|
|
1524
|
-
headerField = "";
|
|
1525
|
-
headerValue = "";
|
|
1526
|
-
entryValue = "";
|
|
1527
|
-
entryName = "";
|
|
1528
|
-
contentType = "";
|
|
1529
|
-
filename = null;
|
|
1530
|
-
entryChunks.length = 0;
|
|
1531
|
-
};
|
|
1532
|
-
parser.onHeaderField = function(ui8a) {
|
|
1533
|
-
headerField += decoder.decode(ui8a, { stream: true });
|
|
1534
|
-
};
|
|
1535
|
-
parser.onHeaderValue = function(ui8a) {
|
|
1536
|
-
headerValue += decoder.decode(ui8a, { stream: true });
|
|
1537
|
-
};
|
|
1538
|
-
parser.onHeaderEnd = function() {
|
|
1539
|
-
headerValue += decoder.decode();
|
|
1540
|
-
headerField = headerField.toLowerCase();
|
|
1541
|
-
if (headerField === "content-disposition") {
|
|
1542
|
-
const m2 = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
|
|
1543
|
-
if (m2) {
|
|
1544
|
-
entryName = m2[2] || m2[3] || "";
|
|
1545
|
-
}
|
|
1546
|
-
filename = _fileName(headerValue);
|
|
1547
|
-
if (filename) {
|
|
1548
|
-
parser.onPartData = appendToFile;
|
|
1549
|
-
parser.onPartEnd = appendFileToFormData;
|
|
1550
|
-
}
|
|
1551
|
-
} else if (headerField === "content-type") {
|
|
1552
|
-
contentType = headerValue;
|
|
1553
|
-
}
|
|
1554
|
-
headerValue = "";
|
|
1555
|
-
headerField = "";
|
|
1556
|
-
};
|
|
1557
|
-
for await (const chunk of Body2) {
|
|
1558
|
-
parser.write(chunk);
|
|
1559
|
-
}
|
|
1560
|
-
parser.end();
|
|
1561
|
-
return formData;
|
|
1562
|
-
}
|
|
1563
|
-
const multipartParser = /* @__PURE__ */ Object.freeze({
|
|
1564
|
-
__proto__: null,
|
|
1565
|
-
toFormData
|
|
1566
|
-
});
|
|
1567
|
-
export {
|
|
1568
|
-
AbortError,
|
|
1569
|
-
Blob,
|
|
1570
|
-
FetchError,
|
|
1571
|
-
File,
|
|
1572
|
-
FormData,
|
|
1573
|
-
Headers,
|
|
1574
|
-
Request,
|
|
1575
|
-
Response,
|
|
1576
|
-
fetch as default,
|
|
1577
|
-
isRedirect
|
|
1578
|
-
};
|
|
1
|
+
import M from"node:http";import fe from"node:https";import N from"node:zlib";import H,{PassThrough as K,pipeline as F}from"node:stream";import{Buffer as T}from"node:buffer";import{d as ue}from"./data-uri-to-buffer.mjs";import{types as J,deprecate as j,promisify as he}from"node:util";import{B as de,F as pe}from"./fetch-blob.mjs";import{F as Z,f as me}from"./formdata-polyfill.mjs";import{format as ge}from"node:url";import{isIP as ye}from"node:net";import"node:fs";import"node:path";import"./node-domexception.mjs";import"./web-streams-polyfill.mjs";import"./react.mjs";class q extends Error{constructor(e,t){super(e),Error.captureStackTrace(this,this.constructor),this.type=t}get name(){return this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}}class U extends q{constructor(e,t,o){super(e,t),o&&(this.code=this.errno=o.code,this.erroredSysCall=o.syscall)}}const Q=Symbol.toStringTag,se=r=>typeof r=="object"&&typeof r.append=="function"&&typeof r.delete=="function"&&typeof r.get=="function"&&typeof r.getAll=="function"&&typeof r.has=="function"&&typeof r.set=="function"&&typeof r.sort=="function"&&r[Q]==="URLSearchParams",X=r=>r&&typeof r=="object"&&typeof r.arrayBuffer=="function"&&typeof r.type=="string"&&typeof r.stream=="function"&&typeof r.constructor=="function"&&/^(Blob|File)$/.test(r[Q]),we=r=>typeof r=="object"&&(r[Q]==="AbortSignal"||r[Q]==="EventTarget"),Ee=(r,e)=>{const t=new URL(e).hostname,o=new URL(r).hostname;return t===o||t.endsWith(`.${o}`)},Te=(r,e)=>{const t=new URL(e).protocol,o=new URL(r).protocol;return t===o},be=he(H.pipeline),A=Symbol("Body internals");class z{constructor(e,{size:t=0}={}){let o=null;e===null?e=null:se(e)?e=T.from(e.toString()):X(e)||T.isBuffer(e)||(J.isAnyArrayBuffer(e)?e=T.from(e):ArrayBuffer.isView(e)?e=T.from(e.buffer,e.byteOffset,e.byteLength):e instanceof H||(e instanceof Z?(e=me(e),o=e.type.split("=")[1]):e=T.from(String(e))));let n=e;T.isBuffer(e)?n=H.Readable.from(e):X(e)&&(n=H.Readable.from(e.stream())),this[A]={body:e,stream:n,boundary:o,disturbed:!1,error:null},this.size=t,e instanceof H&&e.on("error",s=>{const l=s instanceof q?s:new U(`Invalid response body while trying to fetch ${this.url}: ${s.message}`,"system",s);this[A].error=l})}get body(){return this[A].stream}get bodyUsed(){return this[A].disturbed}async arrayBuffer(){const{buffer:e,byteOffset:t,byteLength:o}=await ee(this);return e.slice(t,t+o)}async formData(){const e=this.headers.get("content-type");if(e.startsWith("application/x-www-form-urlencoded")){const o=new Z,n=new URLSearchParams(await this.text());for(const[s,l]of n)o.append(s,l);return o}const{toFormData:t}=await Promise.resolve().then(function(){return Ke});return t(this.body,e)}async blob(){const e=this.headers&&this.headers.get("content-type")||this[A].body&&this[A].body.type||"",t=await this.arrayBuffer();return new de([t],{type:e})}async json(){const e=await this.text();return JSON.parse(e)}async text(){const e=await ee(this);return new TextDecoder().decode(e)}buffer(){return ee(this)}}z.prototype.buffer=j(z.prototype.buffer,"Please use 'response.arrayBuffer()' instead of 'response.buffer()'","node-fetch#buffer");Object.defineProperties(z.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0},data:{get:j(()=>{},"data doesn't exist, use json(), text(), arrayBuffer(), or body instead","https://github.com/node-fetch/node-fetch/issues/1000 (response)")}});async function ee(r){if(r[A].disturbed)throw new TypeError(`body used already for: ${r.url}`);if(r[A].disturbed=!0,r[A].error)throw r[A].error;const{body:e}=r;if(e===null)return T.alloc(0);if(!(e instanceof H))return T.alloc(0);const t=[];let o=0;try{for await(const n of e){if(r.size>0&&o+n.length>r.size){const s=new U(`content size at ${r.url} over limit: ${r.size}`,"max-size");throw e.destroy(s),s}o+=n.length,t.push(n)}}catch(n){throw n instanceof q?n:new U(`Invalid response body while trying to fetch ${r.url}: ${n.message}`,"system",n)}if(e.readableEnded===!0||e._readableState.ended===!0)try{return t.every(n=>typeof n=="string")?T.from(t.join("")):T.concat(t,o)}catch(n){throw new U(`Could not create Buffer from response body for ${r.url}: ${n.message}`,"system",n)}else throw new U(`Premature close of server response while trying to fetch ${r.url}`)}const te=(r,e)=>{let t,o,{body:n}=r[A];if(r.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof H&&typeof n.getBoundary!="function"&&(t=new K({highWaterMark:e}),o=new K({highWaterMark:e}),n.pipe(t),n.pipe(o),r[A].stream=t,n=o),n},Ae=j(r=>r.getBoundary(),"form-data doesn't follow the spec and requires special treatment. Use alternative package","https://github.com/node-fetch/node-fetch/issues/1167"),ie=(r,e)=>r===null?null:typeof r=="string"?"text/plain;charset=UTF-8":se(r)?"application/x-www-form-urlencoded;charset=UTF-8":X(r)?r.type||null:T.isBuffer(r)||J.isAnyArrayBuffer(r)||ArrayBuffer.isView(r)?null:r instanceof Z?`multipart/form-data; boundary=${e[A].boundary}`:r&&typeof r.getBoundary=="function"?`multipart/form-data;boundary=${Ae(r)}`:r instanceof H?null:"text/plain;charset=UTF-8",Re=r=>{const{body:e}=r[A];return e===null?0:X(e)?e.size:T.isBuffer(e)?e.length:e&&typeof e.getLengthSync=="function"&&e.hasKnownLength&&e.hasKnownLength()?e.getLengthSync():null},Se=async(r,{body:e})=>{e===null?r.end():await be(e,r)},G=typeof M.validateHeaderName=="function"?M.validateHeaderName:r=>{if(!/^[\^`\-\w!#$%&'*+.|~]+$/.test(r)){const e=new TypeError(`Header name must be a valid HTTP token [${r}]`);throw Object.defineProperty(e,"code",{value:"ERR_INVALID_HTTP_TOKEN"}),e}},re=typeof M.validateHeaderValue=="function"?M.validateHeaderValue:(r,e)=>{if(/[^\t\u0020-\u007E\u0080-\u00FF]/.test(e)){const t=new TypeError(`Invalid character in header content ["${r}"]`);throw Object.defineProperty(t,"code",{value:"ERR_INVALID_CHAR"}),t}};class k extends URLSearchParams{constructor(e){let t=[];if(e instanceof k){const o=e.raw();for(const[n,s]of Object.entries(o))t.push(...s.map(l=>[n,l]))}else if(e!=null)if(typeof e=="object"&&!J.isBoxedPrimitive(e)){const o=e[Symbol.iterator];if(o==null)t.push(...Object.entries(e));else{if(typeof o!="function")throw new TypeError("Header pairs must be iterable");t=[...e].map(n=>{if(typeof n!="object"||J.isBoxedPrimitive(n))throw new TypeError("Each header pair must be an iterable object");return[...n]}).map(n=>{if(n.length!==2)throw new TypeError("Each header pair must be a name/value tuple");return[...n]})}}else throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");return t=t.length>0?t.map(([o,n])=>(G(o),re(o,String(n)),[String(o).toLowerCase(),String(n)])):void 0,super(t),new Proxy(this,{get(o,n,s){switch(n){case"append":case"set":return(l,f)=>(G(l),re(l,String(f)),URLSearchParams.prototype[n].call(o,String(l).toLowerCase(),String(f)));case"delete":case"has":case"getAll":return l=>(G(l),URLSearchParams.prototype[n].call(o,String(l).toLowerCase()));case"keys":return()=>(o.sort(),new Set(URLSearchParams.prototype.keys.call(o)).keys());default:return Reflect.get(o,n,s)}}})}get[Symbol.toStringTag](){return this.constructor.name}toString(){return Object.prototype.toString.call(this)}get(e){const t=this.getAll(e);if(t.length===0)return null;let o=t.join(", ");return/^content-encoding$/i.test(e)&&(o=o.toLowerCase()),o}forEach(e,t=void 0){for(const o of this.keys())Reflect.apply(e,t,[this.get(o),o,this])}*values(){for(const e of this.keys())yield this.get(e)}*entries(){for(const e of this.keys())yield[e,this.get(e)]}[Symbol.iterator](){return this.entries()}raw(){return[...this.keys()].reduce((e,t)=>(e[t]=this.getAll(t),e),{})}[Symbol.for("nodejs.util.inspect.custom")](){return[...this.keys()].reduce((e,t)=>{const o=this.getAll(t);return t==="host"?e[t]=o[0]:e[t]=o.length>1?o:o[0],e},{})}}Object.defineProperties(k.prototype,["get","entries","forEach","values"].reduce((r,e)=>(r[e]={enumerable:!0},r),{}));function Pe(r=[]){return new k(r.reduce((e,t,o,n)=>(o%2===0&&e.push(n.slice(o,o+2)),e),[]).filter(([e,t])=>{try{return G(e),re(e,String(t)),!0}catch{return!1}}))}const De=new Set([301,302,303,307,308]),ae=r=>De.has(r),L=Symbol("Response internals");class R extends z{constructor(e=null,t={}){super(e,t);const o=t.status!=null?t.status:200,n=new k(t.headers);if(e!==null&&!n.has("Content-Type")){const s=ie(e,this);s&&n.append("Content-Type",s)}this[L]={type:"default",url:t.url,status:o,statusText:t.statusText||"",headers:n,counter:t.counter,highWaterMark:t.highWaterMark}}get type(){return this[L].type}get url(){return this[L].url||""}get status(){return this[L].status}get ok(){return this[L].status>=200&&this[L].status<300}get redirected(){return this[L].counter>0}get statusText(){return this[L].statusText}get headers(){return this[L].headers}get highWaterMark(){return this[L].highWaterMark}clone(){return new R(te(this,this.highWaterMark),{type:this.type,url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected,size:this.size,highWaterMark:this.highWaterMark})}static redirect(e,t=302){if(!ae(t))throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');return new R(null,{headers:{location:new URL(e).toString()},status:t})}static error(){const e=new R(null,{status:0,statusText:""});return e[L].type="error",e}static json(e=void 0,t={}){const o=JSON.stringify(e);if(o===void 0)throw new TypeError("data is not JSON serializable");const n=new k(t&&t.headers);return n.has("content-type")||n.set("content-type","application/json"),new R(o,{...t,headers:n})}get[Symbol.toStringTag](){return"Response"}}Object.defineProperties(R.prototype,{type:{enumerable:!0},url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}});const Le=r=>{if(r.search)return r.search;const e=r.href.length-1,t=r.hash||(r.href[e]==="#"?"#":"");return r.href[e-t.length]==="?"?"?":""};function ne(r,e=!1){return r==null||(r=new URL(r),/^(about|blob|data):$/.test(r.protocol))?"no-referrer":(r.username="",r.password="",r.hash="",e&&(r.pathname="",r.search=""),r)}const ce=new Set(["","no-referrer","no-referrer-when-downgrade","same-origin","origin","strict-origin","origin-when-cross-origin","strict-origin-when-cross-origin","unsafe-url"]),_e="strict-origin-when-cross-origin";function Ue(r){if(!ce.has(r))throw new TypeError(`Invalid referrerPolicy: ${r}`);return r}function He(r){if(/^(http|ws)s:$/.test(r.protocol))return!0;const e=r.host.replace(/(^\[)|(]$)/g,""),t=ye(e);return t===4&&/^127\./.test(e)||t===6&&/^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(e)?!0:r.host==="localhost"||r.host.endsWith(".localhost")?!1:r.protocol==="file:"}function v(r){return/^about:(blank|srcdoc)$/.test(r)||r.protocol==="data:"||/^(blob|filesystem):$/.test(r.protocol)?!0:He(r)}function ke(r,{referrerURLCallback:e,referrerOriginCallback:t}={}){if(r.referrer==="no-referrer"||r.referrerPolicy==="")return null;const o=r.referrerPolicy;if(r.referrer==="about:client")return"no-referrer";const n=r.referrer;let s=ne(n),l=ne(n,!0);s.toString().length>4096&&(s=l),e&&(s=e(s)),t&&(l=t(l));const f=new URL(r.url);switch(o){case"no-referrer":return"no-referrer";case"origin":return l;case"unsafe-url":return s;case"strict-origin":return v(s)&&!v(f)?"no-referrer":l.toString();case"strict-origin-when-cross-origin":return s.origin===f.origin?s:v(s)&&!v(f)?"no-referrer":l;case"same-origin":return s.origin===f.origin?s:"no-referrer";case"origin-when-cross-origin":return s.origin===f.origin?s:l;case"no-referrer-when-downgrade":return v(s)&&!v(f)?"no-referrer":s;default:throw new TypeError(`Invalid referrerPolicy: ${o}`)}}function Be(r){const e=(r.get("referrer-policy")||"").split(/[,\s]+/);let t="";for(const o of e)o&&ce.has(o)&&(t=o);return t}const y=Symbol("Request internals"),$=r=>typeof r=="object"&&typeof r[y]=="object",Oe=j(()=>{},".data is not a valid RequestInit property, use .body instead","https://github.com/node-fetch/node-fetch/issues/1000 (request)");class V extends z{constructor(e,t={}){let o;if($(e)?o=new URL(e.url):(o=new URL(e),e={}),o.username!==""||o.password!=="")throw new TypeError(`${o} is an url with embedded credentials.`);let n=t.method||e.method||"GET";if(/^(delete|get|head|options|post|put)$/i.test(n)&&(n=n.toUpperCase()),!$(t)&&"data"in t&&Oe(),(t.body!=null||$(e)&&e.body!==null)&&(n==="GET"||n==="HEAD"))throw new TypeError("Request with GET/HEAD method cannot have body");const s=t.body?t.body:$(e)&&e.body!==null?te(e):null;super(s,{size:t.size||e.size||0});const l=new k(t.headers||e.headers||{});if(s!==null&&!l.has("Content-Type")){const a=ie(s,this);a&&l.set("Content-Type",a)}let f=$(e)?e.signal:null;if("signal"in t&&(f=t.signal),f!=null&&!we(f))throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");let c=t.referrer==null?e.referrer:t.referrer;if(c==="")c="no-referrer";else if(c){const a=new URL(c);c=/^about:(\/\/)?client$/.test(a)?"client":a}else c=void 0;this[y]={method:n,redirect:t.redirect||e.redirect||"follow",headers:l,parsedURL:o,signal:f,referrer:c},this.follow=t.follow===void 0?e.follow===void 0?20:e.follow:t.follow,this.compress=t.compress===void 0?e.compress===void 0?!0:e.compress:t.compress,this.counter=t.counter||e.counter||0,this.agent=t.agent||e.agent,this.highWaterMark=t.highWaterMark||e.highWaterMark||16384,this.insecureHTTPParser=t.insecureHTTPParser||e.insecureHTTPParser||!1,this.referrerPolicy=t.referrerPolicy||e.referrerPolicy||""}get method(){return this[y].method}get url(){return ge(this[y].parsedURL)}get headers(){return this[y].headers}get redirect(){return this[y].redirect}get signal(){return this[y].signal}get referrer(){if(this[y].referrer==="no-referrer")return"";if(this[y].referrer==="client")return"about:client";if(this[y].referrer)return this[y].referrer.toString()}get referrerPolicy(){return this[y].referrerPolicy}set referrerPolicy(e){this[y].referrerPolicy=Ue(e)}clone(){return new V(this)}get[Symbol.toStringTag](){return"Request"}}Object.defineProperties(V.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}});const xe=r=>{const{parsedURL:e}=r[y],t=new k(r[y].headers);t.has("Accept")||t.set("Accept","*/*");let o=null;if(r.body===null&&/^(post|put)$/i.test(r.method)&&(o="0"),r.body!==null){const f=Re(r);typeof f=="number"&&!Number.isNaN(f)&&(o=String(f))}o&&t.set("Content-Length",o),r.referrerPolicy===""&&(r.referrerPolicy=_e),r.referrer&&r.referrer!=="no-referrer"?r[y].referrer=ke(r):r[y].referrer="no-referrer",r[y].referrer instanceof URL&&t.set("Referer",r.referrer),t.has("User-Agent")||t.set("User-Agent","node-fetch"),r.compress&&!t.has("Accept-Encoding")&&t.set("Accept-Encoding","gzip, deflate, br");let{agent:n}=r;typeof n=="function"&&(n=n(e));const s=Le(e),l={path:e.pathname+s,method:r.method,headers:t[Symbol.for("nodejs.util.inspect.custom")](),insecureHTTPParser:r.insecureHTTPParser,agent:n};return{parsedURL:e,options:l}};class Ne extends q{constructor(e,t="aborted"){super(e,t)}}const Fe=new Set(["data:","http:","https:"]);async function ve(r,e){return new Promise((t,o)=>{const n=new V(r,e),{parsedURL:s,options:l}=xe(n);if(!Fe.has(s.protocol))throw new TypeError(`node-fetch cannot load ${r}. URL scheme "${s.protocol.replace(/:$/,"")}" is not supported.`);if(s.protocol==="data:"){const i=ue(n.url),b=new R(i,{headers:{"Content-Type":i.typeFull}});t(b);return}const f=(s.protocol==="https:"?fe:M).request,{signal:c}=n;let a=null;const g=()=>{const i=new Ne("The operation was aborted.");o(i),n.body&&n.body instanceof H.Readable&&n.body.destroy(i),!(!a||!a.body)&&a.body.emit("error",i)};if(c&&c.aborted){g();return}const P=()=>{g(),D()},S=f(s.toString(),l);c&&c.addEventListener("abort",P);const D=()=>{S.abort(),c&&c.removeEventListener("abort",P)};S.on("error",i=>{o(new U(`request to ${n.url} failed, reason: ${i.message}`,"system",i)),D()}),Ce(S,i=>{a&&a.body&&a.body.destroy(i)}),process.version<"v14"&&S.on("socket",i=>{let b;i.prependListener("end",()=>{b=i._eventsCount}),i.prependListener("close",u=>{if(a&&b<i._eventsCount&&!u){const h=new Error("Premature close");h.code="ERR_STREAM_PREMATURE_CLOSE",a.body.emit("error",h)}})}),S.on("response",i=>{S.setTimeout(0);const b=Pe(i.rawHeaders);if(ae(i.statusCode)){const d=b.get("Location");let E=null;try{E=d===null?null:new URL(d,n.url)}catch{if(n.redirect!=="manual"){o(new U(`uri requested responds with an invalid redirect URL: ${d}`,"invalid-redirect")),D();return}}switch(n.redirect){case"error":o(new U(`uri requested responds with a redirect, redirect mode is set to error: ${n.url}`,"no-redirect")),D();return;case"manual":break;case"follow":{if(E===null)break;if(n.counter>=n.follow){o(new U(`maximum redirect reached at: ${n.url}`,"max-redirect")),D();return}const m={headers:new k(n.headers),follow:n.follow,counter:n.counter+1,agent:n.agent,compress:n.compress,method:n.method,body:te(n),signal:n.signal,size:n.size,referrer:n.referrer,referrerPolicy:n.referrerPolicy};if(!Ee(n.url,E)||!Te(n.url,E))for(const le of["authorization","www-authenticate","cookie","cookie2"])m.headers.delete(le);if(i.statusCode!==303&&n.body&&e.body instanceof H.Readable){o(new U("Cannot follow redirect with body being a readable stream","unsupported-redirect")),D();return}(i.statusCode===303||(i.statusCode===301||i.statusCode===302)&&n.method==="POST")&&(m.method="GET",m.body=void 0,m.headers.delete("content-length"));const C=Be(b);C&&(m.referrerPolicy=C),t(ve(new V(E,m))),D();return}default:return o(new TypeError(`Redirect option '${n.redirect}' is not a valid value of RequestRedirect`))}}c&&i.once("end",()=>{c.removeEventListener("abort",P)});let u=F(i,new K,d=>{d&&o(d)});process.version<"v12.10"&&i.on("aborted",P);const h={url:n.url,status:i.statusCode,statusText:i.statusMessage,headers:b,size:n.size,counter:n.counter,highWaterMark:n.highWaterMark},w=b.get("Content-Encoding");if(!n.compress||n.method==="HEAD"||w===null||i.statusCode===204||i.statusCode===304){a=new R(u,h),t(a);return}const B={flush:N.Z_SYNC_FLUSH,finishFlush:N.Z_SYNC_FLUSH};if(w==="gzip"||w==="x-gzip"){u=F(u,N.createGunzip(B),d=>{d&&o(d)}),a=new R(u,h),t(a);return}if(w==="deflate"||w==="x-deflate"){const d=F(i,new K,E=>{E&&o(E)});d.once("data",E=>{(E[0]&15)===8?u=F(u,N.createInflate(),m=>{m&&o(m)}):u=F(u,N.createInflateRaw(),m=>{m&&o(m)}),a=new R(u,h),t(a)}),d.once("end",()=>{a||(a=new R(u,h),t(a))});return}if(w==="br"){u=F(u,N.createBrotliDecompress(),d=>{d&&o(d)}),a=new R(u,h),t(a);return}a=new R(u,h),t(a)}),Se(S,n).catch(o)})}function Ce(r,e){const t=T.from(`0\r
|
|
2
|
+
\r
|
|
3
|
+
`);let o=!1,n=!1,s;r.on("response",l=>{const{headers:f}=l;o=f["transfer-encoding"]==="chunked"&&!f["content-length"]}),r.on("socket",l=>{const f=()=>{if(o&&!n){const a=new Error("Premature close");a.code="ERR_STREAM_PREMATURE_CLOSE",e(a)}},c=a=>{n=T.compare(a.slice(-5),t)===0,!n&&s&&(n=T.compare(s.slice(-3),t.slice(0,3))===0&&T.compare(a.slice(-2),t.slice(3))===0),s=a};l.prependListener("close",f),l.on("data",c),r.on("close",()=>{l.removeListener("close",f),l.removeListener("data",c)})})}let _=0;const p={START_BOUNDARY:_++,HEADER_FIELD_START:_++,HEADER_FIELD:_++,HEADER_VALUE_START:_++,HEADER_VALUE:_++,HEADER_VALUE_ALMOST_DONE:_++,HEADERS_ALMOST_DONE:_++,PART_DATA_START:_++,PART_DATA:_++,END:_++};let oe=1;const O={PART_BOUNDARY:oe,LAST_BOUNDARY:oe*=2},Y=10,W=13,$e=32,I=45,Ie=58,Me=97,ze=122,Ve=r=>r|32,x=()=>{};class Ye{constructor(e){this.index=0,this.flags=0,this.onHeaderEnd=x,this.onHeaderField=x,this.onHeadersEnd=x,this.onHeaderValue=x,this.onPartBegin=x,this.onPartData=x,this.onPartEnd=x,this.boundaryChars={},e=`\r
|
|
4
|
+
--`+e;const t=new Uint8Array(e.length);for(let o=0;o<e.length;o++)t[o]=e.charCodeAt(o),this.boundaryChars[t[o]]=!0;this.boundary=t,this.lookbehind=new Uint8Array(this.boundary.length+8),this.state=p.START_BOUNDARY}write(e){let t=0;const o=e.length;let n=this.index,{lookbehind:s,boundary:l,boundaryChars:f,index:c,state:a,flags:g}=this;const P=this.boundary.length,S=P-1,D=e.length;let i,b;const u=d=>{this[d+"Mark"]=t},h=d=>{delete this[d+"Mark"]},w=(d,E,m,C)=>{(E===void 0||E!==m)&&this[d](C&&C.subarray(E,m))},B=(d,E)=>{const m=d+"Mark";m in this&&(E?(w(d,this[m],t,e),delete this[m]):(w(d,this[m],e.length,e),this[m]=0))};for(t=0;t<o;t++)switch(i=e[t],a){case p.START_BOUNDARY:if(c===l.length-2){if(i===I)g|=O.LAST_BOUNDARY;else if(i!==W)return;c++;break}else if(c-1===l.length-2){if(g&O.LAST_BOUNDARY&&i===I)a=p.END,g=0;else if(!(g&O.LAST_BOUNDARY)&&i===Y)c=0,w("onPartBegin"),a=p.HEADER_FIELD_START;else return;break}i!==l[c+2]&&(c=-2),i===l[c+2]&&c++;break;case p.HEADER_FIELD_START:a=p.HEADER_FIELD,u("onHeaderField"),c=0;case p.HEADER_FIELD:if(i===W){h("onHeaderField"),a=p.HEADERS_ALMOST_DONE;break}if(c++,i===I)break;if(i===Ie){if(c===1)return;B("onHeaderField",!0),a=p.HEADER_VALUE_START;break}if(b=Ve(i),b<Me||b>ze)return;break;case p.HEADER_VALUE_START:if(i===$e)break;u("onHeaderValue"),a=p.HEADER_VALUE;case p.HEADER_VALUE:i===W&&(B("onHeaderValue",!0),w("onHeaderEnd"),a=p.HEADER_VALUE_ALMOST_DONE);break;case p.HEADER_VALUE_ALMOST_DONE:if(i!==Y)return;a=p.HEADER_FIELD_START;break;case p.HEADERS_ALMOST_DONE:if(i!==Y)return;w("onHeadersEnd"),a=p.PART_DATA_START;break;case p.PART_DATA_START:a=p.PART_DATA,u("onPartData");case p.PART_DATA:if(n=c,c===0){for(t+=S;t<D&&!(e[t]in f);)t+=P;t-=S,i=e[t]}if(c<l.length)l[c]===i?(c===0&&B("onPartData",!0),c++):c=0;else if(c===l.length)c++,i===W?g|=O.PART_BOUNDARY:i===I?g|=O.LAST_BOUNDARY:c=0;else if(c-1===l.length)if(g&O.PART_BOUNDARY){if(c=0,i===Y){g&=~O.PART_BOUNDARY,w("onPartEnd"),w("onPartBegin"),a=p.HEADER_FIELD_START;break}}else g&O.LAST_BOUNDARY&&i===I?(w("onPartEnd"),a=p.END,g=0):c=0;if(c>0)s[c-1]=i;else if(n>0){const d=new Uint8Array(s.buffer,s.byteOffset,s.byteLength);w("onPartData",0,n,d),n=0,u("onPartData"),t--}break;case p.END:break;default:throw new Error(`Unexpected state entered: ${a}`)}B("onHeaderField"),B("onHeaderValue"),B("onPartData"),this.index=c,this.state=a,this.flags=g}end(){if(this.state===p.HEADER_FIELD_START&&this.index===0||this.state===p.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();else if(this.state!==p.END)throw new Error("MultipartParser.end(): stream ended unexpectedly")}}function We(r){const e=r.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!e)return;const t=e[2]||e[3]||"";let o=t.slice(t.lastIndexOf("\\")+1);return o=o.replace(/%22/g,'"'),o=o.replace(/&#(\d{4});/g,(n,s)=>String.fromCharCode(s)),o}async function Ge(r,e){if(!/multipart/i.test(e))throw new TypeError("Failed to fetch");const t=e.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!t)throw new TypeError("no or bad content-type header, no multipart boundary");const o=new Ye(t[1]||t[2]);let n,s,l,f,c,a;const g=[],P=new Z,S=h=>{l+=u.decode(h,{stream:!0})},D=h=>{g.push(h)},i=()=>{const h=new pe(g,a,{type:c});P.append(f,h)},b=()=>{P.append(f,l)},u=new TextDecoder("utf-8");u.decode(),o.onPartBegin=function(){o.onPartData=S,o.onPartEnd=b,n="",s="",l="",f="",c="",a=null,g.length=0},o.onHeaderField=function(h){n+=u.decode(h,{stream:!0})},o.onHeaderValue=function(h){s+=u.decode(h,{stream:!0})},o.onHeaderEnd=function(){if(s+=u.decode(),n=n.toLowerCase(),n==="content-disposition"){const h=s.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);h&&(f=h[2]||h[3]||""),a=We(s),a&&(o.onPartData=D,o.onPartEnd=i)}else n==="content-type"&&(c=s);s="",n=""};for await(const h of r)o.write(h);return o.end(),P}const Ke=Object.freeze({__proto__:null,toFormData:Ge});export{Ne as AbortError,de as Blob,U as FetchError,pe as File,Z as FormData,k as Headers,V as Request,R as Response,ve as default,ae as isRedirect};
|