@actual-app/api 26.4.0 → 26.5.0-nightly.20260407
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/dist/index.js +18 -235
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
- package/dist/from-Bl-Hslp4.js +0 -3842
- package/dist/from-Bl-Hslp4.js.map +0 -1
- package/dist/multipart-parser-BnDysoMr.js +0 -290
- package/dist/multipart-parser-BnDysoMr.js.map +0 -1
- package/dist/src-iMkUmuwR.js +0 -1265
- package/dist/src-iMkUmuwR.js.map +0 -1
package/dist/src-iMkUmuwR.js
DELETED
|
@@ -1,1265 +0,0 @@
|
|
|
1
|
-
const require_index = require("./index.js");
|
|
2
|
-
const require_from = require("./from-Bl-Hslp4.js");
|
|
3
|
-
let node_http = require("node:http");
|
|
4
|
-
node_http = require_index.__toESM(node_http);
|
|
5
|
-
let node_https = require("node:https");
|
|
6
|
-
node_https = require_index.__toESM(node_https);
|
|
7
|
-
let node_zlib = require("node:zlib");
|
|
8
|
-
node_zlib = require_index.__toESM(node_zlib);
|
|
9
|
-
let node_stream = require("node:stream");
|
|
10
|
-
node_stream = require_index.__toESM(node_stream);
|
|
11
|
-
let node_buffer = require("node:buffer");
|
|
12
|
-
let node_util = require("node:util");
|
|
13
|
-
let node_url = require("node:url");
|
|
14
|
-
let node_net = require("node:net");
|
|
15
|
-
//#region ../../node_modules/data-uri-to-buffer/dist/index.js
|
|
16
|
-
/**
|
|
17
|
-
* Returns a `Buffer` instance from the given data URI `uri`.
|
|
18
|
-
*
|
|
19
|
-
* @param {String} uri Data URI to turn into a Buffer instance
|
|
20
|
-
* @returns {Buffer} Buffer instance from Data URI
|
|
21
|
-
* @api public
|
|
22
|
-
*/
|
|
23
|
-
function dataUriToBuffer(uri) {
|
|
24
|
-
if (!/^data:/i.test(uri)) throw new TypeError("`uri` does not appear to be a Data URI (must begin with \"data:\")");
|
|
25
|
-
uri = uri.replace(/\r?\n/g, "");
|
|
26
|
-
const firstComma = uri.indexOf(",");
|
|
27
|
-
if (firstComma === -1 || firstComma <= 4) throw new TypeError("malformed data: URI");
|
|
28
|
-
const meta = uri.substring(5, firstComma).split(";");
|
|
29
|
-
let charset = "";
|
|
30
|
-
let base64 = false;
|
|
31
|
-
const type = meta[0] || "text/plain";
|
|
32
|
-
let typeFull = type;
|
|
33
|
-
for (let i = 1; i < meta.length; i++) if (meta[i] === "base64") base64 = true;
|
|
34
|
-
else if (meta[i]) {
|
|
35
|
-
typeFull += `;${meta[i]}`;
|
|
36
|
-
if (meta[i].indexOf("charset=") === 0) charset = meta[i].substring(8);
|
|
37
|
-
}
|
|
38
|
-
if (!meta[0] && !charset.length) {
|
|
39
|
-
typeFull += ";charset=US-ASCII";
|
|
40
|
-
charset = "US-ASCII";
|
|
41
|
-
}
|
|
42
|
-
const encoding = base64 ? "base64" : "ascii";
|
|
43
|
-
const data = unescape(uri.substring(firstComma + 1));
|
|
44
|
-
const buffer = Buffer.from(data, encoding);
|
|
45
|
-
buffer.type = type;
|
|
46
|
-
buffer.typeFull = typeFull;
|
|
47
|
-
buffer.charset = charset;
|
|
48
|
-
return buffer;
|
|
49
|
-
}
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region ../../node_modules/node-fetch/src/errors/base.js
|
|
52
|
-
var FetchBaseError = class extends Error {
|
|
53
|
-
constructor(message, type) {
|
|
54
|
-
super(message);
|
|
55
|
-
Error.captureStackTrace(this, this.constructor);
|
|
56
|
-
this.type = type;
|
|
57
|
-
}
|
|
58
|
-
get name() {
|
|
59
|
-
return this.constructor.name;
|
|
60
|
-
}
|
|
61
|
-
get [Symbol.toStringTag]() {
|
|
62
|
-
return this.constructor.name;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region ../../node_modules/node-fetch/src/errors/fetch-error.js
|
|
67
|
-
/**
|
|
68
|
-
* @typedef {{ address?: string, code: string, dest?: string, errno: number, info?: object, message: string, path?: string, port?: number, syscall: string}} SystemError
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* FetchError interface for operational errors
|
|
72
|
-
*/
|
|
73
|
-
var FetchError = class extends FetchBaseError {
|
|
74
|
-
/**
|
|
75
|
-
* @param {string} message - Error message for human
|
|
76
|
-
* @param {string} [type] - Error type for machine
|
|
77
|
-
* @param {SystemError} [systemError] - For Node.js system error
|
|
78
|
-
*/
|
|
79
|
-
constructor(message, type, systemError) {
|
|
80
|
-
super(message, type);
|
|
81
|
-
if (systemError) {
|
|
82
|
-
this.code = this.errno = systemError.code;
|
|
83
|
-
this.erroredSysCall = systemError.syscall;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region ../../node_modules/node-fetch/src/utils/is.js
|
|
89
|
-
/**
|
|
90
|
-
* Is.js
|
|
91
|
-
*
|
|
92
|
-
* Object type checks.
|
|
93
|
-
*/
|
|
94
|
-
var NAME = Symbol.toStringTag;
|
|
95
|
-
/**
|
|
96
|
-
* Check if `obj` is a URLSearchParams object
|
|
97
|
-
* ref: https://github.com/node-fetch/node-fetch/issues/296#issuecomment-307598143
|
|
98
|
-
* @param {*} object - Object to check for
|
|
99
|
-
* @return {boolean}
|
|
100
|
-
*/
|
|
101
|
-
var isURLSearchParameters = (object) => {
|
|
102
|
-
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";
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Check if `object` is a W3C `Blob` object (which `File` inherits from)
|
|
106
|
-
* @param {*} object - Object to check for
|
|
107
|
-
* @return {boolean}
|
|
108
|
-
*/
|
|
109
|
-
var isBlob = (object) => {
|
|
110
|
-
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]);
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Check if `obj` is an instance of AbortSignal.
|
|
114
|
-
* @param {*} object - Object to check for
|
|
115
|
-
* @return {boolean}
|
|
116
|
-
*/
|
|
117
|
-
var isAbortSignal = (object) => {
|
|
118
|
-
return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* isDomainOrSubdomain reports whether sub is a subdomain (or exact match) of
|
|
122
|
-
* the parent domain.
|
|
123
|
-
*
|
|
124
|
-
* Both domains must already be in canonical form.
|
|
125
|
-
* @param {string|URL} original
|
|
126
|
-
* @param {string|URL} destination
|
|
127
|
-
*/
|
|
128
|
-
var isDomainOrSubdomain = (destination, original) => {
|
|
129
|
-
const orig = new URL(original).hostname;
|
|
130
|
-
const dest = new URL(destination).hostname;
|
|
131
|
-
return orig === dest || orig.endsWith(`.${dest}`);
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* isSameProtocol reports whether the two provided URLs use the same protocol.
|
|
135
|
-
*
|
|
136
|
-
* Both domains must already be in canonical form.
|
|
137
|
-
* @param {string|URL} original
|
|
138
|
-
* @param {string|URL} destination
|
|
139
|
-
*/
|
|
140
|
-
var isSameProtocol = (destination, original) => {
|
|
141
|
-
return new URL(original).protocol === new URL(destination).protocol;
|
|
142
|
-
};
|
|
143
|
-
//#endregion
|
|
144
|
-
//#region ../../node_modules/node-fetch/src/body.js
|
|
145
|
-
/**
|
|
146
|
-
* Body.js
|
|
147
|
-
*
|
|
148
|
-
* Body interface provides common methods for Request and Response
|
|
149
|
-
*/
|
|
150
|
-
var pipeline = (0, node_util.promisify)(node_stream.default.pipeline);
|
|
151
|
-
var INTERNALS$2 = Symbol("Body internals");
|
|
152
|
-
/**
|
|
153
|
-
* Body mixin
|
|
154
|
-
*
|
|
155
|
-
* Ref: https://fetch.spec.whatwg.org/#body
|
|
156
|
-
*
|
|
157
|
-
* @param Stream body Readable stream
|
|
158
|
-
* @param Object opts Response options
|
|
159
|
-
* @return Void
|
|
160
|
-
*/
|
|
161
|
-
var Body = class {
|
|
162
|
-
constructor(body, { size = 0 } = {}) {
|
|
163
|
-
let boundary = null;
|
|
164
|
-
if (body === null) body = null;
|
|
165
|
-
else if (isURLSearchParameters(body)) body = node_buffer.Buffer.from(body.toString());
|
|
166
|
-
else if (isBlob(body)) {} else if (node_buffer.Buffer.isBuffer(body)) {} else if (node_util.types.isAnyArrayBuffer(body)) body = node_buffer.Buffer.from(body);
|
|
167
|
-
else if (ArrayBuffer.isView(body)) body = node_buffer.Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
168
|
-
else if (body instanceof node_stream.default) {} else if (body instanceof require_from.FormData) {
|
|
169
|
-
body = require_from.formDataToBlob(body);
|
|
170
|
-
boundary = body.type.split("=")[1];
|
|
171
|
-
} else body = node_buffer.Buffer.from(String(body));
|
|
172
|
-
let stream = body;
|
|
173
|
-
if (node_buffer.Buffer.isBuffer(body)) stream = node_stream.default.Readable.from(body);
|
|
174
|
-
else if (isBlob(body)) stream = node_stream.default.Readable.from(body.stream());
|
|
175
|
-
this[INTERNALS$2] = {
|
|
176
|
-
body,
|
|
177
|
-
stream,
|
|
178
|
-
boundary,
|
|
179
|
-
disturbed: false,
|
|
180
|
-
error: null
|
|
181
|
-
};
|
|
182
|
-
this.size = size;
|
|
183
|
-
if (body instanceof node_stream.default) body.on("error", (error_) => {
|
|
184
|
-
const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
|
|
185
|
-
this[INTERNALS$2].error = error;
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
get body() {
|
|
189
|
-
return this[INTERNALS$2].stream;
|
|
190
|
-
}
|
|
191
|
-
get bodyUsed() {
|
|
192
|
-
return this[INTERNALS$2].disturbed;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Decode response as ArrayBuffer
|
|
196
|
-
*
|
|
197
|
-
* @return Promise
|
|
198
|
-
*/
|
|
199
|
-
async arrayBuffer() {
|
|
200
|
-
const { buffer, byteOffset, byteLength } = await consumeBody(this);
|
|
201
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
202
|
-
}
|
|
203
|
-
async formData() {
|
|
204
|
-
const ct = this.headers.get("content-type");
|
|
205
|
-
if (ct.startsWith("application/x-www-form-urlencoded")) {
|
|
206
|
-
const formData = new require_from.FormData();
|
|
207
|
-
const parameters = new URLSearchParams(await this.text());
|
|
208
|
-
for (const [name, value] of parameters) formData.append(name, value);
|
|
209
|
-
return formData;
|
|
210
|
-
}
|
|
211
|
-
const { toFormData } = await Promise.resolve().then(() => require("./multipart-parser-BnDysoMr.js"));
|
|
212
|
-
return toFormData(this.body, ct);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Return raw response as Blob
|
|
216
|
-
*
|
|
217
|
-
* @return Promise
|
|
218
|
-
*/
|
|
219
|
-
async blob() {
|
|
220
|
-
const ct = this.headers && this.headers.get("content-type") || this[INTERNALS$2].body && this[INTERNALS$2].body.type || "";
|
|
221
|
-
return new require_from.Blob([await this.arrayBuffer()], { type: ct });
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Decode response as json
|
|
225
|
-
*
|
|
226
|
-
* @return Promise
|
|
227
|
-
*/
|
|
228
|
-
async json() {
|
|
229
|
-
const text = await this.text();
|
|
230
|
-
return JSON.parse(text);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Decode response as text
|
|
234
|
-
*
|
|
235
|
-
* @return Promise
|
|
236
|
-
*/
|
|
237
|
-
async text() {
|
|
238
|
-
const buffer = await consumeBody(this);
|
|
239
|
-
return new TextDecoder().decode(buffer);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Decode response as buffer (non-spec api)
|
|
243
|
-
*
|
|
244
|
-
* @return Promise
|
|
245
|
-
*/
|
|
246
|
-
buffer() {
|
|
247
|
-
return consumeBody(this);
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
Body.prototype.buffer = (0, node_util.deprecate)(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
|
|
251
|
-
Object.defineProperties(Body.prototype, {
|
|
252
|
-
body: { enumerable: true },
|
|
253
|
-
bodyUsed: { enumerable: true },
|
|
254
|
-
arrayBuffer: { enumerable: true },
|
|
255
|
-
blob: { enumerable: true },
|
|
256
|
-
json: { enumerable: true },
|
|
257
|
-
text: { enumerable: true },
|
|
258
|
-
data: { get: (0, node_util.deprecate)(() => {}, "data doesn't exist, use json(), text(), arrayBuffer(), or body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (response)") }
|
|
259
|
-
});
|
|
260
|
-
/**
|
|
261
|
-
* Consume and convert an entire Body to a Buffer.
|
|
262
|
-
*
|
|
263
|
-
* Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
|
|
264
|
-
*
|
|
265
|
-
* @return Promise
|
|
266
|
-
*/
|
|
267
|
-
async function consumeBody(data) {
|
|
268
|
-
if (data[INTERNALS$2].disturbed) throw new TypeError(`body used already for: ${data.url}`);
|
|
269
|
-
data[INTERNALS$2].disturbed = true;
|
|
270
|
-
if (data[INTERNALS$2].error) throw data[INTERNALS$2].error;
|
|
271
|
-
const { body } = data;
|
|
272
|
-
if (body === null) return node_buffer.Buffer.alloc(0);
|
|
273
|
-
/* c8 ignore next 3 */
|
|
274
|
-
if (!(body instanceof node_stream.default)) return node_buffer.Buffer.alloc(0);
|
|
275
|
-
const accum = [];
|
|
276
|
-
let accumBytes = 0;
|
|
277
|
-
try {
|
|
278
|
-
for await (const chunk of body) {
|
|
279
|
-
if (data.size > 0 && accumBytes + chunk.length > data.size) {
|
|
280
|
-
const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
|
|
281
|
-
body.destroy(error);
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
accumBytes += chunk.length;
|
|
285
|
-
accum.push(chunk);
|
|
286
|
-
}
|
|
287
|
-
} catch (error) {
|
|
288
|
-
throw error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
|
|
289
|
-
}
|
|
290
|
-
if (body.readableEnded === true || body._readableState.ended === true) try {
|
|
291
|
-
if (accum.every((c) => typeof c === "string")) return node_buffer.Buffer.from(accum.join(""));
|
|
292
|
-
return node_buffer.Buffer.concat(accum, accumBytes);
|
|
293
|
-
} catch (error) {
|
|
294
|
-
throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
|
|
295
|
-
}
|
|
296
|
-
else throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Clone body given Res/Req instance
|
|
300
|
-
*
|
|
301
|
-
* @param Mixed instance Response or Request instance
|
|
302
|
-
* @param String highWaterMark highWaterMark for both PassThrough body streams
|
|
303
|
-
* @return Mixed
|
|
304
|
-
*/
|
|
305
|
-
var clone = (instance, highWaterMark) => {
|
|
306
|
-
let p1;
|
|
307
|
-
let p2;
|
|
308
|
-
let { body } = instance[INTERNALS$2];
|
|
309
|
-
if (instance.bodyUsed) throw new Error("cannot clone body after it is used");
|
|
310
|
-
if (body instanceof node_stream.default && typeof body.getBoundary !== "function") {
|
|
311
|
-
p1 = new node_stream.PassThrough({ highWaterMark });
|
|
312
|
-
p2 = new node_stream.PassThrough({ highWaterMark });
|
|
313
|
-
body.pipe(p1);
|
|
314
|
-
body.pipe(p2);
|
|
315
|
-
instance[INTERNALS$2].stream = p1;
|
|
316
|
-
body = p2;
|
|
317
|
-
}
|
|
318
|
-
return body;
|
|
319
|
-
};
|
|
320
|
-
var getNonSpecFormDataBoundary = (0, node_util.deprecate)((body) => body.getBoundary(), "form-data doesn't follow the spec and requires special treatment. Use alternative package", "https://github.com/node-fetch/node-fetch/issues/1167");
|
|
321
|
-
/**
|
|
322
|
-
* Performs the operation "extract a `Content-Type` value from |object|" as
|
|
323
|
-
* specified in the specification:
|
|
324
|
-
* https://fetch.spec.whatwg.org/#concept-bodyinit-extract
|
|
325
|
-
*
|
|
326
|
-
* This function assumes that instance.body is present.
|
|
327
|
-
*
|
|
328
|
-
* @param {any} body Any options.body input
|
|
329
|
-
* @returns {string | null}
|
|
330
|
-
*/
|
|
331
|
-
var extractContentType = (body, request) => {
|
|
332
|
-
if (body === null) return null;
|
|
333
|
-
if (typeof body === "string") return "text/plain;charset=UTF-8";
|
|
334
|
-
if (isURLSearchParameters(body)) return "application/x-www-form-urlencoded;charset=UTF-8";
|
|
335
|
-
if (isBlob(body)) return body.type || null;
|
|
336
|
-
if (node_buffer.Buffer.isBuffer(body) || node_util.types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) return null;
|
|
337
|
-
if (body instanceof require_from.FormData) return `multipart/form-data; boundary=${request[INTERNALS$2].boundary}`;
|
|
338
|
-
if (body && typeof body.getBoundary === "function") return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
|
|
339
|
-
if (body instanceof node_stream.default) return null;
|
|
340
|
-
return "text/plain;charset=UTF-8";
|
|
341
|
-
};
|
|
342
|
-
/**
|
|
343
|
-
* The Fetch Standard treats this as if "total bytes" is a property on the body.
|
|
344
|
-
* For us, we have to explicitly get it with a function.
|
|
345
|
-
*
|
|
346
|
-
* ref: https://fetch.spec.whatwg.org/#concept-body-total-bytes
|
|
347
|
-
*
|
|
348
|
-
* @param {any} obj.body Body object from the Body instance.
|
|
349
|
-
* @returns {number | null}
|
|
350
|
-
*/
|
|
351
|
-
var getTotalBytes = (request) => {
|
|
352
|
-
const { body } = request[INTERNALS$2];
|
|
353
|
-
if (body === null) return 0;
|
|
354
|
-
if (isBlob(body)) return body.size;
|
|
355
|
-
if (node_buffer.Buffer.isBuffer(body)) return body.length;
|
|
356
|
-
if (body && typeof body.getLengthSync === "function") return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
|
|
357
|
-
return null;
|
|
358
|
-
};
|
|
359
|
-
/**
|
|
360
|
-
* Write a Body to a Node.js WritableStream (e.g. http.Request) object.
|
|
361
|
-
*
|
|
362
|
-
* @param {Stream.Writable} dest The stream to write to.
|
|
363
|
-
* @param obj.body Body object from the Body instance.
|
|
364
|
-
* @returns {Promise<void>}
|
|
365
|
-
*/
|
|
366
|
-
var writeToStream = async (dest, { body }) => {
|
|
367
|
-
if (body === null) dest.end();
|
|
368
|
-
else await pipeline(body, dest);
|
|
369
|
-
};
|
|
370
|
-
//#endregion
|
|
371
|
-
//#region ../../node_modules/node-fetch/src/headers.js
|
|
372
|
-
/**
|
|
373
|
-
* Headers.js
|
|
374
|
-
*
|
|
375
|
-
* Headers class offers convenient helpers
|
|
376
|
-
*/
|
|
377
|
-
/* c8 ignore next 9 */
|
|
378
|
-
var validateHeaderName = typeof node_http.default.validateHeaderName === "function" ? node_http.default.validateHeaderName : (name) => {
|
|
379
|
-
if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
|
|
380
|
-
const error = /* @__PURE__ */ new TypeError(`Header name must be a valid HTTP token [${name}]`);
|
|
381
|
-
Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
|
|
382
|
-
throw error;
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
/* c8 ignore next 9 */
|
|
386
|
-
var validateHeaderValue = typeof node_http.default.validateHeaderValue === "function" ? node_http.default.validateHeaderValue : (name, value) => {
|
|
387
|
-
if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
|
|
388
|
-
const error = /* @__PURE__ */ new TypeError(`Invalid character in header content ["${name}"]`);
|
|
389
|
-
Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
|
|
390
|
-
throw error;
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
/**
|
|
394
|
-
* @typedef {Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>} HeadersInit
|
|
395
|
-
*/
|
|
396
|
-
/**
|
|
397
|
-
* This Fetch API interface allows you to perform various actions on HTTP request and response headers.
|
|
398
|
-
* These actions include retrieving, setting, adding to, and removing.
|
|
399
|
-
* A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs.
|
|
400
|
-
* You can add to this using methods like append() (see Examples.)
|
|
401
|
-
* In all methods of this interface, header names are matched by case-insensitive byte sequence.
|
|
402
|
-
*
|
|
403
|
-
*/
|
|
404
|
-
var Headers = class Headers extends URLSearchParams {
|
|
405
|
-
/**
|
|
406
|
-
* Headers class
|
|
407
|
-
*
|
|
408
|
-
* @constructor
|
|
409
|
-
* @param {HeadersInit} [init] - Response headers
|
|
410
|
-
*/
|
|
411
|
-
constructor(init) {
|
|
412
|
-
/** @type {string[][]} */
|
|
413
|
-
let result = [];
|
|
414
|
-
if (init instanceof Headers) {
|
|
415
|
-
const raw = init.raw();
|
|
416
|
-
for (const [name, values] of Object.entries(raw)) result.push(...values.map((value) => [name, value]));
|
|
417
|
-
} else if (init == null) {} else if (typeof init === "object" && !node_util.types.isBoxedPrimitive(init)) {
|
|
418
|
-
const method = init[Symbol.iterator];
|
|
419
|
-
if (method == null) result.push(...Object.entries(init));
|
|
420
|
-
else {
|
|
421
|
-
if (typeof method !== "function") throw new TypeError("Header pairs must be iterable");
|
|
422
|
-
result = [...init].map((pair) => {
|
|
423
|
-
if (typeof pair !== "object" || node_util.types.isBoxedPrimitive(pair)) throw new TypeError("Each header pair must be an iterable object");
|
|
424
|
-
return [...pair];
|
|
425
|
-
}).map((pair) => {
|
|
426
|
-
if (pair.length !== 2) throw new TypeError("Each header pair must be a name/value tuple");
|
|
427
|
-
return [...pair];
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
} else throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
|
|
431
|
-
result = result.length > 0 ? result.map(([name, value]) => {
|
|
432
|
-
validateHeaderName(name);
|
|
433
|
-
validateHeaderValue(name, String(value));
|
|
434
|
-
return [String(name).toLowerCase(), String(value)];
|
|
435
|
-
}) : void 0;
|
|
436
|
-
super(result);
|
|
437
|
-
return new Proxy(this, { get(target, p, receiver) {
|
|
438
|
-
switch (p) {
|
|
439
|
-
case "append":
|
|
440
|
-
case "set": return (name, value) => {
|
|
441
|
-
validateHeaderName(name);
|
|
442
|
-
validateHeaderValue(name, String(value));
|
|
443
|
-
return URLSearchParams.prototype[p].call(target, String(name).toLowerCase(), String(value));
|
|
444
|
-
};
|
|
445
|
-
case "delete":
|
|
446
|
-
case "has":
|
|
447
|
-
case "getAll": return (name) => {
|
|
448
|
-
validateHeaderName(name);
|
|
449
|
-
return URLSearchParams.prototype[p].call(target, String(name).toLowerCase());
|
|
450
|
-
};
|
|
451
|
-
case "keys": return () => {
|
|
452
|
-
target.sort();
|
|
453
|
-
return new Set(URLSearchParams.prototype.keys.call(target)).keys();
|
|
454
|
-
};
|
|
455
|
-
default: return Reflect.get(target, p, receiver);
|
|
456
|
-
}
|
|
457
|
-
} });
|
|
458
|
-
/* c8 ignore next */
|
|
459
|
-
}
|
|
460
|
-
get [Symbol.toStringTag]() {
|
|
461
|
-
return this.constructor.name;
|
|
462
|
-
}
|
|
463
|
-
toString() {
|
|
464
|
-
return Object.prototype.toString.call(this);
|
|
465
|
-
}
|
|
466
|
-
get(name) {
|
|
467
|
-
const values = this.getAll(name);
|
|
468
|
-
if (values.length === 0) return null;
|
|
469
|
-
let value = values.join(", ");
|
|
470
|
-
if (/^content-encoding$/i.test(name)) value = value.toLowerCase();
|
|
471
|
-
return value;
|
|
472
|
-
}
|
|
473
|
-
forEach(callback, thisArg = void 0) {
|
|
474
|
-
for (const name of this.keys()) Reflect.apply(callback, thisArg, [
|
|
475
|
-
this.get(name),
|
|
476
|
-
name,
|
|
477
|
-
this
|
|
478
|
-
]);
|
|
479
|
-
}
|
|
480
|
-
*values() {
|
|
481
|
-
for (const name of this.keys()) yield this.get(name);
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* @type {() => IterableIterator<[string, string]>}
|
|
485
|
-
*/
|
|
486
|
-
*entries() {
|
|
487
|
-
for (const name of this.keys()) yield [name, this.get(name)];
|
|
488
|
-
}
|
|
489
|
-
[Symbol.iterator]() {
|
|
490
|
-
return this.entries();
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Node-fetch non-spec method
|
|
494
|
-
* returning all headers and their values as array
|
|
495
|
-
* @returns {Record<string, string[]>}
|
|
496
|
-
*/
|
|
497
|
-
raw() {
|
|
498
|
-
return [...this.keys()].reduce((result, key) => {
|
|
499
|
-
result[key] = this.getAll(key);
|
|
500
|
-
return result;
|
|
501
|
-
}, {});
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* For better console.log(headers) and also to convert Headers into Node.js Request compatible format
|
|
505
|
-
*/
|
|
506
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
507
|
-
return [...this.keys()].reduce((result, key) => {
|
|
508
|
-
const values = this.getAll(key);
|
|
509
|
-
if (key === "host") result[key] = values[0];
|
|
510
|
-
else result[key] = values.length > 1 ? values : values[0];
|
|
511
|
-
return result;
|
|
512
|
-
}, {});
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
/**
|
|
516
|
-
* Re-shaping object for Web IDL tests
|
|
517
|
-
* Only need to do it for overridden methods
|
|
518
|
-
*/
|
|
519
|
-
Object.defineProperties(Headers.prototype, [
|
|
520
|
-
"get",
|
|
521
|
-
"entries",
|
|
522
|
-
"forEach",
|
|
523
|
-
"values"
|
|
524
|
-
].reduce((result, property) => {
|
|
525
|
-
result[property] = { enumerable: true };
|
|
526
|
-
return result;
|
|
527
|
-
}, {}));
|
|
528
|
-
/**
|
|
529
|
-
* Create a Headers object from an http.IncomingMessage.rawHeaders, ignoring those that do
|
|
530
|
-
* not conform to HTTP grammar productions.
|
|
531
|
-
* @param {import('http').IncomingMessage['rawHeaders']} headers
|
|
532
|
-
*/
|
|
533
|
-
function fromRawHeaders(headers = []) {
|
|
534
|
-
return new Headers(headers.reduce((result, value, index, array) => {
|
|
535
|
-
if (index % 2 === 0) result.push(array.slice(index, index + 2));
|
|
536
|
-
return result;
|
|
537
|
-
}, []).filter(([name, value]) => {
|
|
538
|
-
try {
|
|
539
|
-
validateHeaderName(name);
|
|
540
|
-
validateHeaderValue(name, String(value));
|
|
541
|
-
return true;
|
|
542
|
-
} catch {
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
}));
|
|
546
|
-
}
|
|
547
|
-
//#endregion
|
|
548
|
-
//#region ../../node_modules/node-fetch/src/utils/is-redirect.js
|
|
549
|
-
var redirectStatus = new Set([
|
|
550
|
-
301,
|
|
551
|
-
302,
|
|
552
|
-
303,
|
|
553
|
-
307,
|
|
554
|
-
308
|
|
555
|
-
]);
|
|
556
|
-
/**
|
|
557
|
-
* Redirect code matching
|
|
558
|
-
*
|
|
559
|
-
* @param {number} code - Status code
|
|
560
|
-
* @return {boolean}
|
|
561
|
-
*/
|
|
562
|
-
var isRedirect = (code) => {
|
|
563
|
-
return redirectStatus.has(code);
|
|
564
|
-
};
|
|
565
|
-
//#endregion
|
|
566
|
-
//#region ../../node_modules/node-fetch/src/response.js
|
|
567
|
-
/**
|
|
568
|
-
* Response.js
|
|
569
|
-
*
|
|
570
|
-
* Response class provides content decoding
|
|
571
|
-
*/
|
|
572
|
-
var INTERNALS$1 = Symbol("Response internals");
|
|
573
|
-
/**
|
|
574
|
-
* Response class
|
|
575
|
-
*
|
|
576
|
-
* Ref: https://fetch.spec.whatwg.org/#response-class
|
|
577
|
-
*
|
|
578
|
-
* @param Stream body Readable stream
|
|
579
|
-
* @param Object opts Response options
|
|
580
|
-
* @return Void
|
|
581
|
-
*/
|
|
582
|
-
var Response = class Response extends Body {
|
|
583
|
-
constructor(body = null, options = {}) {
|
|
584
|
-
super(body, options);
|
|
585
|
-
const status = options.status != null ? options.status : 200;
|
|
586
|
-
const headers = new Headers(options.headers);
|
|
587
|
-
if (body !== null && !headers.has("Content-Type")) {
|
|
588
|
-
const contentType = extractContentType(body, this);
|
|
589
|
-
if (contentType) headers.append("Content-Type", contentType);
|
|
590
|
-
}
|
|
591
|
-
this[INTERNALS$1] = {
|
|
592
|
-
type: "default",
|
|
593
|
-
url: options.url,
|
|
594
|
-
status,
|
|
595
|
-
statusText: options.statusText || "",
|
|
596
|
-
headers,
|
|
597
|
-
counter: options.counter,
|
|
598
|
-
highWaterMark: options.highWaterMark
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
get type() {
|
|
602
|
-
return this[INTERNALS$1].type;
|
|
603
|
-
}
|
|
604
|
-
get url() {
|
|
605
|
-
return this[INTERNALS$1].url || "";
|
|
606
|
-
}
|
|
607
|
-
get status() {
|
|
608
|
-
return this[INTERNALS$1].status;
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Convenience property representing if the request ended normally
|
|
612
|
-
*/
|
|
613
|
-
get ok() {
|
|
614
|
-
return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
|
|
615
|
-
}
|
|
616
|
-
get redirected() {
|
|
617
|
-
return this[INTERNALS$1].counter > 0;
|
|
618
|
-
}
|
|
619
|
-
get statusText() {
|
|
620
|
-
return this[INTERNALS$1].statusText;
|
|
621
|
-
}
|
|
622
|
-
get headers() {
|
|
623
|
-
return this[INTERNALS$1].headers;
|
|
624
|
-
}
|
|
625
|
-
get highWaterMark() {
|
|
626
|
-
return this[INTERNALS$1].highWaterMark;
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Clone this response
|
|
630
|
-
*
|
|
631
|
-
* @return Response
|
|
632
|
-
*/
|
|
633
|
-
clone() {
|
|
634
|
-
return new Response(clone(this, this.highWaterMark), {
|
|
635
|
-
type: this.type,
|
|
636
|
-
url: this.url,
|
|
637
|
-
status: this.status,
|
|
638
|
-
statusText: this.statusText,
|
|
639
|
-
headers: this.headers,
|
|
640
|
-
ok: this.ok,
|
|
641
|
-
redirected: this.redirected,
|
|
642
|
-
size: this.size,
|
|
643
|
-
highWaterMark: this.highWaterMark
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* @param {string} url The URL that the new response is to originate from.
|
|
648
|
-
* @param {number} status An optional status code for the response (e.g., 302.)
|
|
649
|
-
* @returns {Response} A Response object.
|
|
650
|
-
*/
|
|
651
|
-
static redirect(url, status = 302) {
|
|
652
|
-
if (!isRedirect(status)) throw new RangeError("Failed to execute \"redirect\" on \"response\": Invalid status code");
|
|
653
|
-
return new Response(null, {
|
|
654
|
-
headers: { location: new URL(url).toString() },
|
|
655
|
-
status
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
static error() {
|
|
659
|
-
const response = new Response(null, {
|
|
660
|
-
status: 0,
|
|
661
|
-
statusText: ""
|
|
662
|
-
});
|
|
663
|
-
response[INTERNALS$1].type = "error";
|
|
664
|
-
return response;
|
|
665
|
-
}
|
|
666
|
-
static json(data = void 0, init = {}) {
|
|
667
|
-
const body = JSON.stringify(data);
|
|
668
|
-
if (body === void 0) throw new TypeError("data is not JSON serializable");
|
|
669
|
-
const headers = new Headers(init && init.headers);
|
|
670
|
-
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
671
|
-
return new Response(body, {
|
|
672
|
-
...init,
|
|
673
|
-
headers
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
get [Symbol.toStringTag]() {
|
|
677
|
-
return "Response";
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
Object.defineProperties(Response.prototype, {
|
|
681
|
-
type: { enumerable: true },
|
|
682
|
-
url: { enumerable: true },
|
|
683
|
-
status: { enumerable: true },
|
|
684
|
-
ok: { enumerable: true },
|
|
685
|
-
redirected: { enumerable: true },
|
|
686
|
-
statusText: { enumerable: true },
|
|
687
|
-
headers: { enumerable: true },
|
|
688
|
-
clone: { enumerable: true }
|
|
689
|
-
});
|
|
690
|
-
//#endregion
|
|
691
|
-
//#region ../../node_modules/node-fetch/src/utils/get-search.js
|
|
692
|
-
var getSearch = (parsedURL) => {
|
|
693
|
-
if (parsedURL.search) return parsedURL.search;
|
|
694
|
-
const lastOffset = parsedURL.href.length - 1;
|
|
695
|
-
const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
|
|
696
|
-
return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
|
|
697
|
-
};
|
|
698
|
-
//#endregion
|
|
699
|
-
//#region ../../node_modules/node-fetch/src/utils/referrer.js
|
|
700
|
-
/**
|
|
701
|
-
* @external URL
|
|
702
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/URL|URL}
|
|
703
|
-
*/
|
|
704
|
-
/**
|
|
705
|
-
* @module utils/referrer
|
|
706
|
-
* @private
|
|
707
|
-
*/
|
|
708
|
-
/**
|
|
709
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#strip-url|Referrer Policy §8.4. Strip url for use as a referrer}
|
|
710
|
-
* @param {string} URL
|
|
711
|
-
* @param {boolean} [originOnly=false]
|
|
712
|
-
*/
|
|
713
|
-
function stripURLForUseAsAReferrer(url, originOnly = false) {
|
|
714
|
-
if (url == null) return "no-referrer";
|
|
715
|
-
url = new URL(url);
|
|
716
|
-
if (/^(about|blob|data):$/.test(url.protocol)) return "no-referrer";
|
|
717
|
-
url.username = "";
|
|
718
|
-
url.password = "";
|
|
719
|
-
url.hash = "";
|
|
720
|
-
if (originOnly) {
|
|
721
|
-
url.pathname = "";
|
|
722
|
-
url.search = "";
|
|
723
|
-
}
|
|
724
|
-
return url;
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#enumdef-referrerpolicy|enum ReferrerPolicy}
|
|
728
|
-
*/
|
|
729
|
-
var ReferrerPolicy = new Set([
|
|
730
|
-
"",
|
|
731
|
-
"no-referrer",
|
|
732
|
-
"no-referrer-when-downgrade",
|
|
733
|
-
"same-origin",
|
|
734
|
-
"origin",
|
|
735
|
-
"strict-origin",
|
|
736
|
-
"origin-when-cross-origin",
|
|
737
|
-
"strict-origin-when-cross-origin",
|
|
738
|
-
"unsafe-url"
|
|
739
|
-
]);
|
|
740
|
-
/**
|
|
741
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#default-referrer-policy|default referrer policy}
|
|
742
|
-
*/
|
|
743
|
-
var DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
|
|
744
|
-
/**
|
|
745
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#referrer-policies|Referrer Policy §3. Referrer Policies}
|
|
746
|
-
* @param {string} referrerPolicy
|
|
747
|
-
* @returns {string} referrerPolicy
|
|
748
|
-
*/
|
|
749
|
-
function validateReferrerPolicy(referrerPolicy) {
|
|
750
|
-
if (!ReferrerPolicy.has(referrerPolicy)) throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
|
|
751
|
-
return referrerPolicy;
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* @see {@link https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy|Referrer Policy §3.2. Is origin potentially trustworthy?}
|
|
755
|
-
* @param {external:URL} url
|
|
756
|
-
* @returns `true`: "Potentially Trustworthy", `false`: "Not Trustworthy"
|
|
757
|
-
*/
|
|
758
|
-
function isOriginPotentiallyTrustworthy(url) {
|
|
759
|
-
if (/^(http|ws)s:$/.test(url.protocol)) return true;
|
|
760
|
-
const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
|
|
761
|
-
const hostIPVersion = (0, node_net.isIP)(hostIp);
|
|
762
|
-
if (hostIPVersion === 4 && /^127\./.test(hostIp)) return true;
|
|
763
|
-
if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) return true;
|
|
764
|
-
if (url.host === "localhost" || url.host.endsWith(".localhost")) return false;
|
|
765
|
-
if (url.protocol === "file:") return true;
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* @see {@link https://w3c.github.io/webappsec-secure-contexts/#is-url-trustworthy|Referrer Policy §3.3. Is url potentially trustworthy?}
|
|
770
|
-
* @param {external:URL} url
|
|
771
|
-
* @returns `true`: "Potentially Trustworthy", `false`: "Not Trustworthy"
|
|
772
|
-
*/
|
|
773
|
-
function isUrlPotentiallyTrustworthy(url) {
|
|
774
|
-
if (/^about:(blank|srcdoc)$/.test(url)) return true;
|
|
775
|
-
if (url.protocol === "data:") return true;
|
|
776
|
-
if (/^(blob|filesystem):$/.test(url.protocol)) return true;
|
|
777
|
-
return isOriginPotentiallyTrustworthy(url);
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Modifies the referrerURL to enforce any extra security policy considerations.
|
|
781
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer|Referrer Policy §8.3. Determine request's Referrer}, step 7
|
|
782
|
-
* @callback module:utils/referrer~referrerURLCallback
|
|
783
|
-
* @param {external:URL} referrerURL
|
|
784
|
-
* @returns {external:URL} modified referrerURL
|
|
785
|
-
*/
|
|
786
|
-
/**
|
|
787
|
-
* Modifies the referrerOrigin to enforce any extra security policy considerations.
|
|
788
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer|Referrer Policy §8.3. Determine request's Referrer}, step 7
|
|
789
|
-
* @callback module:utils/referrer~referrerOriginCallback
|
|
790
|
-
* @param {external:URL} referrerOrigin
|
|
791
|
-
* @returns {external:URL} modified referrerOrigin
|
|
792
|
-
*/
|
|
793
|
-
/**
|
|
794
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer|Referrer Policy §8.3. Determine request's Referrer}
|
|
795
|
-
* @param {Request} request
|
|
796
|
-
* @param {object} o
|
|
797
|
-
* @param {module:utils/referrer~referrerURLCallback} o.referrerURLCallback
|
|
798
|
-
* @param {module:utils/referrer~referrerOriginCallback} o.referrerOriginCallback
|
|
799
|
-
* @returns {external:URL} Request's referrer
|
|
800
|
-
*/
|
|
801
|
-
function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
|
|
802
|
-
if (request.referrer === "no-referrer" || request.referrerPolicy === "") return null;
|
|
803
|
-
const policy = request.referrerPolicy;
|
|
804
|
-
if (request.referrer === "about:client") return "no-referrer";
|
|
805
|
-
const referrerSource = request.referrer;
|
|
806
|
-
let referrerURL = stripURLForUseAsAReferrer(referrerSource);
|
|
807
|
-
let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
|
|
808
|
-
if (referrerURL.toString().length > 4096) referrerURL = referrerOrigin;
|
|
809
|
-
if (referrerURLCallback) referrerURL = referrerURLCallback(referrerURL);
|
|
810
|
-
if (referrerOriginCallback) referrerOrigin = referrerOriginCallback(referrerOrigin);
|
|
811
|
-
const currentURL = new URL(request.url);
|
|
812
|
-
switch (policy) {
|
|
813
|
-
case "no-referrer": return "no-referrer";
|
|
814
|
-
case "origin": return referrerOrigin;
|
|
815
|
-
case "unsafe-url": return referrerURL;
|
|
816
|
-
case "strict-origin":
|
|
817
|
-
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) return "no-referrer";
|
|
818
|
-
return referrerOrigin.toString();
|
|
819
|
-
case "strict-origin-when-cross-origin":
|
|
820
|
-
if (referrerURL.origin === currentURL.origin) return referrerURL;
|
|
821
|
-
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) return "no-referrer";
|
|
822
|
-
return referrerOrigin;
|
|
823
|
-
case "same-origin":
|
|
824
|
-
if (referrerURL.origin === currentURL.origin) return referrerURL;
|
|
825
|
-
return "no-referrer";
|
|
826
|
-
case "origin-when-cross-origin":
|
|
827
|
-
if (referrerURL.origin === currentURL.origin) return referrerURL;
|
|
828
|
-
return referrerOrigin;
|
|
829
|
-
case "no-referrer-when-downgrade":
|
|
830
|
-
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) return "no-referrer";
|
|
831
|
-
return referrerURL;
|
|
832
|
-
default: throw new TypeError(`Invalid referrerPolicy: ${policy}`);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* @see {@link https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header|Referrer Policy §8.1. Parse a referrer policy from a Referrer-Policy header}
|
|
837
|
-
* @param {Headers} headers Response headers
|
|
838
|
-
* @returns {string} policy
|
|
839
|
-
*/
|
|
840
|
-
function parseReferrerPolicyFromHeader(headers) {
|
|
841
|
-
const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
|
|
842
|
-
let policy = "";
|
|
843
|
-
for (const token of policyTokens) if (token && ReferrerPolicy.has(token)) policy = token;
|
|
844
|
-
return policy;
|
|
845
|
-
}
|
|
846
|
-
//#endregion
|
|
847
|
-
//#region ../../node_modules/node-fetch/src/request.js
|
|
848
|
-
/**
|
|
849
|
-
* Request.js
|
|
850
|
-
*
|
|
851
|
-
* Request class contains server only options
|
|
852
|
-
*
|
|
853
|
-
* All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
|
|
854
|
-
*/
|
|
855
|
-
var INTERNALS = Symbol("Request internals");
|
|
856
|
-
/**
|
|
857
|
-
* Check if `obj` is an instance of Request.
|
|
858
|
-
*
|
|
859
|
-
* @param {*} object
|
|
860
|
-
* @return {boolean}
|
|
861
|
-
*/
|
|
862
|
-
var isRequest = (object) => {
|
|
863
|
-
return typeof object === "object" && typeof object[INTERNALS] === "object";
|
|
864
|
-
};
|
|
865
|
-
var doBadDataWarn = (0, node_util.deprecate)(() => {}, ".data is not a valid RequestInit property, use .body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (request)");
|
|
866
|
-
/**
|
|
867
|
-
* Request class
|
|
868
|
-
*
|
|
869
|
-
* Ref: https://fetch.spec.whatwg.org/#request-class
|
|
870
|
-
*
|
|
871
|
-
* @param Mixed input Url or Request instance
|
|
872
|
-
* @param Object init Custom options
|
|
873
|
-
* @return Void
|
|
874
|
-
*/
|
|
875
|
-
var Request = class Request extends Body {
|
|
876
|
-
constructor(input, init = {}) {
|
|
877
|
-
let parsedURL;
|
|
878
|
-
if (isRequest(input)) parsedURL = new URL(input.url);
|
|
879
|
-
else {
|
|
880
|
-
parsedURL = new URL(input);
|
|
881
|
-
input = {};
|
|
882
|
-
}
|
|
883
|
-
if (parsedURL.username !== "" || parsedURL.password !== "") throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
|
|
884
|
-
let method = init.method || input.method || "GET";
|
|
885
|
-
if (/^(delete|get|head|options|post|put)$/i.test(method)) method = method.toUpperCase();
|
|
886
|
-
if (!isRequest(init) && "data" in init) doBadDataWarn();
|
|
887
|
-
if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) throw new TypeError("Request with GET/HEAD method cannot have body");
|
|
888
|
-
const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
|
|
889
|
-
super(inputBody, { size: init.size || input.size || 0 });
|
|
890
|
-
const headers = new Headers(init.headers || input.headers || {});
|
|
891
|
-
if (inputBody !== null && !headers.has("Content-Type")) {
|
|
892
|
-
const contentType = extractContentType(inputBody, this);
|
|
893
|
-
if (contentType) headers.set("Content-Type", contentType);
|
|
894
|
-
}
|
|
895
|
-
let signal = isRequest(input) ? input.signal : null;
|
|
896
|
-
if ("signal" in init) signal = init.signal;
|
|
897
|
-
if (signal != null && !isAbortSignal(signal)) throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
|
|
898
|
-
let referrer = init.referrer == null ? input.referrer : init.referrer;
|
|
899
|
-
if (referrer === "") referrer = "no-referrer";
|
|
900
|
-
else if (referrer) {
|
|
901
|
-
const parsedReferrer = new URL(referrer);
|
|
902
|
-
referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
|
|
903
|
-
} else referrer = void 0;
|
|
904
|
-
this[INTERNALS] = {
|
|
905
|
-
method,
|
|
906
|
-
redirect: init.redirect || input.redirect || "follow",
|
|
907
|
-
headers,
|
|
908
|
-
parsedURL,
|
|
909
|
-
signal,
|
|
910
|
-
referrer
|
|
911
|
-
};
|
|
912
|
-
this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
|
|
913
|
-
this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
|
|
914
|
-
this.counter = init.counter || input.counter || 0;
|
|
915
|
-
this.agent = init.agent || input.agent;
|
|
916
|
-
this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
|
|
917
|
-
this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
|
|
918
|
-
this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
|
|
919
|
-
}
|
|
920
|
-
/** @returns {string} */
|
|
921
|
-
get method() {
|
|
922
|
-
return this[INTERNALS].method;
|
|
923
|
-
}
|
|
924
|
-
/** @returns {string} */
|
|
925
|
-
get url() {
|
|
926
|
-
return (0, node_url.format)(this[INTERNALS].parsedURL);
|
|
927
|
-
}
|
|
928
|
-
/** @returns {Headers} */
|
|
929
|
-
get headers() {
|
|
930
|
-
return this[INTERNALS].headers;
|
|
931
|
-
}
|
|
932
|
-
get redirect() {
|
|
933
|
-
return this[INTERNALS].redirect;
|
|
934
|
-
}
|
|
935
|
-
/** @returns {AbortSignal} */
|
|
936
|
-
get signal() {
|
|
937
|
-
return this[INTERNALS].signal;
|
|
938
|
-
}
|
|
939
|
-
get referrer() {
|
|
940
|
-
if (this[INTERNALS].referrer === "no-referrer") return "";
|
|
941
|
-
if (this[INTERNALS].referrer === "client") return "about:client";
|
|
942
|
-
if (this[INTERNALS].referrer) return this[INTERNALS].referrer.toString();
|
|
943
|
-
}
|
|
944
|
-
get referrerPolicy() {
|
|
945
|
-
return this[INTERNALS].referrerPolicy;
|
|
946
|
-
}
|
|
947
|
-
set referrerPolicy(referrerPolicy) {
|
|
948
|
-
this[INTERNALS].referrerPolicy = validateReferrerPolicy(referrerPolicy);
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Clone this request
|
|
952
|
-
*
|
|
953
|
-
* @return Request
|
|
954
|
-
*/
|
|
955
|
-
clone() {
|
|
956
|
-
return new Request(this);
|
|
957
|
-
}
|
|
958
|
-
get [Symbol.toStringTag]() {
|
|
959
|
-
return "Request";
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
Object.defineProperties(Request.prototype, {
|
|
963
|
-
method: { enumerable: true },
|
|
964
|
-
url: { enumerable: true },
|
|
965
|
-
headers: { enumerable: true },
|
|
966
|
-
redirect: { enumerable: true },
|
|
967
|
-
clone: { enumerable: true },
|
|
968
|
-
signal: { enumerable: true },
|
|
969
|
-
referrer: { enumerable: true },
|
|
970
|
-
referrerPolicy: { enumerable: true }
|
|
971
|
-
});
|
|
972
|
-
/**
|
|
973
|
-
* Convert a Request to Node.js http request options.
|
|
974
|
-
*
|
|
975
|
-
* @param {Request} request - A Request instance
|
|
976
|
-
* @return The options object to be passed to http.request
|
|
977
|
-
*/
|
|
978
|
-
var getNodeRequestOptions = (request) => {
|
|
979
|
-
const { parsedURL } = request[INTERNALS];
|
|
980
|
-
const headers = new Headers(request[INTERNALS].headers);
|
|
981
|
-
if (!headers.has("Accept")) headers.set("Accept", "*/*");
|
|
982
|
-
let contentLengthValue = null;
|
|
983
|
-
if (request.body === null && /^(post|put)$/i.test(request.method)) contentLengthValue = "0";
|
|
984
|
-
if (request.body !== null) {
|
|
985
|
-
const totalBytes = getTotalBytes(request);
|
|
986
|
-
if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) contentLengthValue = String(totalBytes);
|
|
987
|
-
}
|
|
988
|
-
if (contentLengthValue) headers.set("Content-Length", contentLengthValue);
|
|
989
|
-
if (request.referrerPolicy === "") request.referrerPolicy = DEFAULT_REFERRER_POLICY;
|
|
990
|
-
if (request.referrer && request.referrer !== "no-referrer") request[INTERNALS].referrer = determineRequestsReferrer(request);
|
|
991
|
-
else request[INTERNALS].referrer = "no-referrer";
|
|
992
|
-
if (request[INTERNALS].referrer instanceof URL) headers.set("Referer", request.referrer);
|
|
993
|
-
if (!headers.has("User-Agent")) headers.set("User-Agent", "node-fetch");
|
|
994
|
-
if (request.compress && !headers.has("Accept-Encoding")) headers.set("Accept-Encoding", "gzip, deflate, br");
|
|
995
|
-
let { agent } = request;
|
|
996
|
-
if (typeof agent === "function") agent = agent(parsedURL);
|
|
997
|
-
const search = getSearch(parsedURL);
|
|
998
|
-
return {
|
|
999
|
-
parsedURL,
|
|
1000
|
-
options: {
|
|
1001
|
-
path: parsedURL.pathname + search,
|
|
1002
|
-
method: request.method,
|
|
1003
|
-
headers: headers[Symbol.for("nodejs.util.inspect.custom")](),
|
|
1004
|
-
insecureHTTPParser: request.insecureHTTPParser,
|
|
1005
|
-
agent
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
};
|
|
1009
|
-
//#endregion
|
|
1010
|
-
//#region ../../node_modules/node-fetch/src/errors/abort-error.js
|
|
1011
|
-
/**
|
|
1012
|
-
* AbortError interface for cancelled requests
|
|
1013
|
-
*/
|
|
1014
|
-
var AbortError = class extends FetchBaseError {
|
|
1015
|
-
constructor(message, type = "aborted") {
|
|
1016
|
-
super(message, type);
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
//#endregion
|
|
1020
|
-
//#region ../../node_modules/node-fetch/src/index.js
|
|
1021
|
-
/**
|
|
1022
|
-
* Index.js
|
|
1023
|
-
*
|
|
1024
|
-
* a request API compatible with window.fetch
|
|
1025
|
-
*
|
|
1026
|
-
* All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
|
|
1027
|
-
*/
|
|
1028
|
-
var supportedSchemas = new Set([
|
|
1029
|
-
"data:",
|
|
1030
|
-
"http:",
|
|
1031
|
-
"https:"
|
|
1032
|
-
]);
|
|
1033
|
-
/**
|
|
1034
|
-
* Fetch function
|
|
1035
|
-
*
|
|
1036
|
-
* @param {string | URL | import('./request').default} url - Absolute url or Request instance
|
|
1037
|
-
* @param {*} [options_] - Fetch options
|
|
1038
|
-
* @return {Promise<import('./response').default>}
|
|
1039
|
-
*/
|
|
1040
|
-
async function fetch(url, options_) {
|
|
1041
|
-
return new Promise((resolve, reject) => {
|
|
1042
|
-
const request = new Request(url, options_);
|
|
1043
|
-
const { parsedURL, options } = getNodeRequestOptions(request);
|
|
1044
|
-
if (!supportedSchemas.has(parsedURL.protocol)) throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
|
|
1045
|
-
if (parsedURL.protocol === "data:") {
|
|
1046
|
-
const data = dataUriToBuffer(request.url);
|
|
1047
|
-
resolve(new Response(data, { headers: { "Content-Type": data.typeFull } }));
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
|
-
const send = (parsedURL.protocol === "https:" ? node_https.default : node_http.default).request;
|
|
1051
|
-
const { signal } = request;
|
|
1052
|
-
let response = null;
|
|
1053
|
-
const abort = () => {
|
|
1054
|
-
const error = new AbortError("The operation was aborted.");
|
|
1055
|
-
reject(error);
|
|
1056
|
-
if (request.body && request.body instanceof node_stream.default.Readable) request.body.destroy(error);
|
|
1057
|
-
if (!response || !response.body) return;
|
|
1058
|
-
response.body.emit("error", error);
|
|
1059
|
-
};
|
|
1060
|
-
if (signal && signal.aborted) {
|
|
1061
|
-
abort();
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
|
-
const abortAndFinalize = () => {
|
|
1065
|
-
abort();
|
|
1066
|
-
finalize();
|
|
1067
|
-
};
|
|
1068
|
-
const request_ = send(parsedURL.toString(), options);
|
|
1069
|
-
if (signal) signal.addEventListener("abort", abortAndFinalize);
|
|
1070
|
-
const finalize = () => {
|
|
1071
|
-
request_.abort();
|
|
1072
|
-
if (signal) signal.removeEventListener("abort", abortAndFinalize);
|
|
1073
|
-
};
|
|
1074
|
-
request_.on("error", (error) => {
|
|
1075
|
-
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
|
|
1076
|
-
finalize();
|
|
1077
|
-
});
|
|
1078
|
-
fixResponseChunkedTransferBadEnding(request_, (error) => {
|
|
1079
|
-
if (response && response.body) response.body.destroy(error);
|
|
1080
|
-
});
|
|
1081
|
-
/* c8 ignore next 18 */
|
|
1082
|
-
if (process.version < "v14") request_.on("socket", (s) => {
|
|
1083
|
-
let endedWithEventsCount;
|
|
1084
|
-
s.prependListener("end", () => {
|
|
1085
|
-
endedWithEventsCount = s._eventsCount;
|
|
1086
|
-
});
|
|
1087
|
-
s.prependListener("close", (hadError) => {
|
|
1088
|
-
if (response && endedWithEventsCount < s._eventsCount && !hadError) {
|
|
1089
|
-
const error = /* @__PURE__ */ new Error("Premature close");
|
|
1090
|
-
error.code = "ERR_STREAM_PREMATURE_CLOSE";
|
|
1091
|
-
response.body.emit("error", error);
|
|
1092
|
-
}
|
|
1093
|
-
});
|
|
1094
|
-
});
|
|
1095
|
-
request_.on("response", (response_) => {
|
|
1096
|
-
request_.setTimeout(0);
|
|
1097
|
-
const headers = fromRawHeaders(response_.rawHeaders);
|
|
1098
|
-
if (isRedirect(response_.statusCode)) {
|
|
1099
|
-
const location = headers.get("Location");
|
|
1100
|
-
let locationURL = null;
|
|
1101
|
-
try {
|
|
1102
|
-
locationURL = location === null ? null : new URL(location, request.url);
|
|
1103
|
-
} catch {
|
|
1104
|
-
if (request.redirect !== "manual") {
|
|
1105
|
-
reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
|
|
1106
|
-
finalize();
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
switch (request.redirect) {
|
|
1111
|
-
case "error":
|
|
1112
|
-
reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
|
|
1113
|
-
finalize();
|
|
1114
|
-
return;
|
|
1115
|
-
case "manual": break;
|
|
1116
|
-
case "follow": {
|
|
1117
|
-
if (locationURL === null) break;
|
|
1118
|
-
if (request.counter >= request.follow) {
|
|
1119
|
-
reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
|
|
1120
|
-
finalize();
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
const requestOptions = {
|
|
1124
|
-
headers: new Headers(request.headers),
|
|
1125
|
-
follow: request.follow,
|
|
1126
|
-
counter: request.counter + 1,
|
|
1127
|
-
agent: request.agent,
|
|
1128
|
-
compress: request.compress,
|
|
1129
|
-
method: request.method,
|
|
1130
|
-
body: clone(request),
|
|
1131
|
-
signal: request.signal,
|
|
1132
|
-
size: request.size,
|
|
1133
|
-
referrer: request.referrer,
|
|
1134
|
-
referrerPolicy: request.referrerPolicy
|
|
1135
|
-
};
|
|
1136
|
-
if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) for (const name of [
|
|
1137
|
-
"authorization",
|
|
1138
|
-
"www-authenticate",
|
|
1139
|
-
"cookie",
|
|
1140
|
-
"cookie2"
|
|
1141
|
-
]) requestOptions.headers.delete(name);
|
|
1142
|
-
if (response_.statusCode !== 303 && request.body && options_.body instanceof node_stream.default.Readable) {
|
|
1143
|
-
reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
|
|
1144
|
-
finalize();
|
|
1145
|
-
return;
|
|
1146
|
-
}
|
|
1147
|
-
if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
|
|
1148
|
-
requestOptions.method = "GET";
|
|
1149
|
-
requestOptions.body = void 0;
|
|
1150
|
-
requestOptions.headers.delete("content-length");
|
|
1151
|
-
}
|
|
1152
|
-
const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
|
|
1153
|
-
if (responseReferrerPolicy) requestOptions.referrerPolicy = responseReferrerPolicy;
|
|
1154
|
-
resolve(fetch(new Request(locationURL, requestOptions)));
|
|
1155
|
-
finalize();
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
default: return reject(/* @__PURE__ */ new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
if (signal) response_.once("end", () => {
|
|
1162
|
-
signal.removeEventListener("abort", abortAndFinalize);
|
|
1163
|
-
});
|
|
1164
|
-
let body = (0, node_stream.pipeline)(response_, new node_stream.PassThrough(), (error) => {
|
|
1165
|
-
if (error) reject(error);
|
|
1166
|
-
});
|
|
1167
|
-
/* c8 ignore next 3 */
|
|
1168
|
-
if (process.version < "v12.10") response_.on("aborted", abortAndFinalize);
|
|
1169
|
-
const responseOptions = {
|
|
1170
|
-
url: request.url,
|
|
1171
|
-
status: response_.statusCode,
|
|
1172
|
-
statusText: response_.statusMessage,
|
|
1173
|
-
headers,
|
|
1174
|
-
size: request.size,
|
|
1175
|
-
counter: request.counter,
|
|
1176
|
-
highWaterMark: request.highWaterMark
|
|
1177
|
-
};
|
|
1178
|
-
const codings = headers.get("Content-Encoding");
|
|
1179
|
-
if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
|
|
1180
|
-
response = new Response(body, responseOptions);
|
|
1181
|
-
resolve(response);
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
const zlibOptions = {
|
|
1185
|
-
flush: node_zlib.default.Z_SYNC_FLUSH,
|
|
1186
|
-
finishFlush: node_zlib.default.Z_SYNC_FLUSH
|
|
1187
|
-
};
|
|
1188
|
-
if (codings === "gzip" || codings === "x-gzip") {
|
|
1189
|
-
body = (0, node_stream.pipeline)(body, node_zlib.default.createGunzip(zlibOptions), (error) => {
|
|
1190
|
-
if (error) reject(error);
|
|
1191
|
-
});
|
|
1192
|
-
response = new Response(body, responseOptions);
|
|
1193
|
-
resolve(response);
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
if (codings === "deflate" || codings === "x-deflate") {
|
|
1197
|
-
const raw = (0, node_stream.pipeline)(response_, new node_stream.PassThrough(), (error) => {
|
|
1198
|
-
if (error) reject(error);
|
|
1199
|
-
});
|
|
1200
|
-
raw.once("data", (chunk) => {
|
|
1201
|
-
if ((chunk[0] & 15) === 8) body = (0, node_stream.pipeline)(body, node_zlib.default.createInflate(), (error) => {
|
|
1202
|
-
if (error) reject(error);
|
|
1203
|
-
});
|
|
1204
|
-
else body = (0, node_stream.pipeline)(body, node_zlib.default.createInflateRaw(), (error) => {
|
|
1205
|
-
if (error) reject(error);
|
|
1206
|
-
});
|
|
1207
|
-
response = new Response(body, responseOptions);
|
|
1208
|
-
resolve(response);
|
|
1209
|
-
});
|
|
1210
|
-
raw.once("end", () => {
|
|
1211
|
-
if (!response) {
|
|
1212
|
-
response = new Response(body, responseOptions);
|
|
1213
|
-
resolve(response);
|
|
1214
|
-
}
|
|
1215
|
-
});
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
if (codings === "br") {
|
|
1219
|
-
body = (0, node_stream.pipeline)(body, node_zlib.default.createBrotliDecompress(), (error) => {
|
|
1220
|
-
if (error) reject(error);
|
|
1221
|
-
});
|
|
1222
|
-
response = new Response(body, responseOptions);
|
|
1223
|
-
resolve(response);
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
response = new Response(body, responseOptions);
|
|
1227
|
-
resolve(response);
|
|
1228
|
-
});
|
|
1229
|
-
writeToStream(request_, request).catch(reject);
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
1233
|
-
const LAST_CHUNK = node_buffer.Buffer.from("0\r\n\r\n");
|
|
1234
|
-
let isChunkedTransfer = false;
|
|
1235
|
-
let properLastChunkReceived = false;
|
|
1236
|
-
let previousChunk;
|
|
1237
|
-
request.on("response", (response) => {
|
|
1238
|
-
const { headers } = response;
|
|
1239
|
-
isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
|
|
1240
|
-
});
|
|
1241
|
-
request.on("socket", (socket) => {
|
|
1242
|
-
const onSocketClose = () => {
|
|
1243
|
-
if (isChunkedTransfer && !properLastChunkReceived) {
|
|
1244
|
-
const error = /* @__PURE__ */ new Error("Premature close");
|
|
1245
|
-
error.code = "ERR_STREAM_PREMATURE_CLOSE";
|
|
1246
|
-
errorCallback(error);
|
|
1247
|
-
}
|
|
1248
|
-
};
|
|
1249
|
-
const onData = (buf) => {
|
|
1250
|
-
properLastChunkReceived = node_buffer.Buffer.compare(buf.slice(-5), LAST_CHUNK) === 0;
|
|
1251
|
-
if (!properLastChunkReceived && previousChunk) properLastChunkReceived = node_buffer.Buffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && node_buffer.Buffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
|
|
1252
|
-
previousChunk = buf;
|
|
1253
|
-
};
|
|
1254
|
-
socket.prependListener("close", onSocketClose);
|
|
1255
|
-
socket.on("data", onData);
|
|
1256
|
-
request.on("close", () => {
|
|
1257
|
-
socket.removeListener("close", onSocketClose);
|
|
1258
|
-
socket.removeListener("data", onData);
|
|
1259
|
-
});
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
//#endregion
|
|
1263
|
-
exports.default = fetch;
|
|
1264
|
-
|
|
1265
|
-
//# sourceMappingURL=src-iMkUmuwR.js.map
|