node_modules: update (#349)

Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
Dawid Dziurlaanddawidd6 authored and GitHub committed 2026-10-18 15:39:30 +02:00
1 parent 9d0c26ec8b
commit 0a1f5db16c
36 files changed
+1934 -648

No files matched your search

+5
View File
@@ -27,6 +27,8 @@ export interface FetchOptions {
} | undefined;
/** Socket inactivity timeout in milliseconds, defaults to 60000, 0 disables it */
timeout?: number | undefined;
/** Time limit for the whole request in milliseconds, redirects included, defaults to 120000, 0 disables it */
maxTime?: number | undefined;
/** Maximum size of the (decoded) response body in bytes, defaults to 64 MB, Infinity disables the limit */
maxBytes?: number | undefined;
/** Maximum number of redirects to follow (default 5) */
@@ -37,6 +39,8 @@ export interface FetchOptions {
redirects?: number | undefined;
/** Response stream shared across redirects, set by nmfetch itself */
fetchRes?: FetchResponse | undefined;
/** Timestamp the whole request has to be done by, shared across redirects, set by nmfetch itself */
deadline?: number | undefined;
}
/**
* The stream nmfetch returns. The response body is piped into it, the status code and
@@ -50,6 +54,7 @@ declare function nmfetch(url: string, options?: FetchOptions): FetchResponse;
declare namespace nmfetch {
var Cookies: typeof import("./cookies.js").default;
var DEFAULT_TIMEOUT: number;
var DEFAULT_MAX_TIME: number;
}
type CookiesJar = Cookies;
/**
+30
View File
@@ -49,6 +49,10 @@ const objects_js_1 = require("../shared/objects.js");
const MAX_REDIRECTS = 5;
// a stalled server would otherwise hold the request, and whatever waits on it, open forever
const DEFAULT_TIMEOUT = 60 * 1000;
// the inactivity timeout above is reset by every byte, so a server dripping one within each
// window could still hold the request, and the message being built from it, open for as
// long as it liked. The whole request, redirects included, has to be done within this
const DEFAULT_MAX_TIME = 2 * 60 * 1000;
// the body is usually buffered in memory by the caller, so an unbounded download is refused
const DEFAULT_MAX_BYTES = 64 * 1024 * 1024;
// Only genuine TLS settings are taken from options.tls. That object reaches us straight
@@ -126,6 +130,12 @@ function nmfetch(url, options) {
options.cookies = options.cookies || new cookies_js_1.default();
options.redirects = options.redirects || 0;
options.maxRedirects = isNaN(options.maxRedirects) ? MAX_REDIRECTS : options.maxRedirects;
if (!options.deadline) {
options.maxTime = typeof options.maxTime === 'number' && options.maxTime >= 0 ? options.maxTime : DEFAULT_MAX_TIME;
// the one deadline is shared with the requests the redirects lead to, every hop
// gets the time that is left rather than starting over
options.deadline = options.maxTime ? Date.now() + options.maxTime : 0;
}
const fetchRes = options.fetchRes;
const parsed = parseFetchUrl(url);
if (!parsed) {
@@ -271,12 +281,22 @@ function nmfetch(url, options) {
});
return fetchRes;
}
// the whole request has to be done by options.deadline, see maxTime. The timer is
// released on every way out of the request, so it never outlives it
let deadlineTimer;
const clearDeadline = () => {
if (deadlineTimer) {
clearTimeout(deadlineTimer);
deadlineTimer = undefined;
}
};
// reports the first failure of this request on fetchRes and releases the request
const fail = (err, sourceUrl = url) => {
if (finished) {
return;
}
finished = true;
clearDeadline();
setFetchCode(err);
err.sourceUrl = sourceUrl;
fetchRes.emit('error', err);
@@ -286,10 +306,16 @@ function nmfetch(url, options) {
if (timeout) {
req.setTimeout(timeout, () => fail(new Error('Request Timeout')));
}
if (options.deadline) {
deadlineTimer = setTimeout(() => fail(new Error('Request exceeded the allowed ' + options.maxTime + ' ms')), Math.max(options.deadline - Date.now(), 1));
// a pending deadline is no reason to keep the process alive
deadlineTimer.unref();
}
req.on('error', (err) => fail(err));
// a consumer that destroys the response stream before it ended does not want the rest of
// the body, release the request now instead of when the timeout fires
fetchRes.once('close', () => {
clearDeadline();
if (finished || fetchRes.readableEnded) {
return;
}
@@ -358,6 +384,7 @@ function nmfetch(url, options) {
// this request is done with, release it so its socket and timeout do not
// outlive it and report a late error on the shared fetchRes
finished = true;
clearDeadline();
res.resume();
req.abort();
return nmfetch(redirectUrl, options);
@@ -368,6 +395,8 @@ function nmfetch(url, options) {
return fail(new Error('Invalid status code ' + res.statusCode));
}
res.on('error', (err) => fail(err));
// the response is in, whatever is left of it is in memory and no longer on the network
res.once('end', () => clearDeadline());
const maxBytes = typeof options.maxBytes === 'number' && options.maxBytes > 0 ? options.maxBytes : DEFAULT_MAX_BYTES;
const source = inflate || res;
let received = 0;
@@ -405,6 +434,7 @@ function nmfetch(url, options) {
}
nmfetch.Cookies = cookies_js_1.default;
nmfetch.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
nmfetch.DEFAULT_MAX_TIME = DEFAULT_MAX_TIME;
exports.default = nmfetch;
module.exports = exports.default;
Object.defineProperty(module.exports, 'default', { value: exports.default, enumerable: false, writable: true, configurable: true });