This commit is contained in:
Vendored
+242
-80
@@ -6,7 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
try {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
} catch (e) {
|
||||
throw mod = 0, e;
|
||||
}
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
@@ -2041,13 +2045,21 @@ var require_dispatcher_base = __commonJS({
|
||||
var kOnDestroyed = /* @__PURE__ */ Symbol("onDestroyed");
|
||||
var kOnClosed = /* @__PURE__ */ Symbol("onClosed");
|
||||
var kInterceptedDispatch = /* @__PURE__ */ Symbol("Intercepted Dispatch");
|
||||
var kWebSocketOptions = /* @__PURE__ */ Symbol("webSocketOptions");
|
||||
var DispatcherBase = class extends Dispatcher {
|
||||
constructor() {
|
||||
constructor(opts) {
|
||||
super();
|
||||
this[kDestroyed] = false;
|
||||
this[kOnDestroyed] = null;
|
||||
this[kClosed] = false;
|
||||
this[kOnClosed] = [];
|
||||
this[kWebSocketOptions] = opts?.webSocket ?? {};
|
||||
}
|
||||
get webSocketOptions() {
|
||||
return {
|
||||
maxFragments: this[kWebSocketOptions].maxFragments ?? 131072,
|
||||
maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? 128 * 1024 * 1024
|
||||
};
|
||||
}
|
||||
get destroyed() {
|
||||
return this[kDestroyed];
|
||||
@@ -5700,6 +5712,9 @@ var require_client_h1 = __commonJS({
|
||||
var FastBuffer = Buffer[Symbol.species];
|
||||
var addListener = util.addListener;
|
||||
var removeAllListeners = util.removeAllListeners;
|
||||
var kIdleSocketValidation = /* @__PURE__ */ Symbol("kIdleSocketValidation");
|
||||
var kIdleSocketValidationTimeout = /* @__PURE__ */ Symbol("kIdleSocketValidationTimeout");
|
||||
var kSocketUsed = /* @__PURE__ */ Symbol("kSocketUsed");
|
||||
var extractBody;
|
||||
async function lazyllhttp() {
|
||||
const llhttpWasmData = process.env.JEST_WORKER_ID ? require_llhttp_wasm() : void 0;
|
||||
@@ -5862,24 +5877,55 @@ var require_client_h1 = __commonJS({
|
||||
currentBufferRef = null;
|
||||
}
|
||||
const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr;
|
||||
if (ret === constants3.ERROR.PAUSED_UPGRADE) {
|
||||
this.onUpgrade(data.slice(offset));
|
||||
} else if (ret === constants3.ERROR.PAUSED) {
|
||||
this.paused = true;
|
||||
socket.unshift(data.slice(offset));
|
||||
} else if (ret !== constants3.ERROR.OK) {
|
||||
const ptr = llhttp.llhttp_get_error_reason(this.ptr);
|
||||
let message = "";
|
||||
if (ptr) {
|
||||
const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0);
|
||||
message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")";
|
||||
if (ret !== constants3.ERROR.OK) {
|
||||
const body = data.subarray(offset);
|
||||
if (ret === constants3.ERROR.PAUSED_UPGRADE) {
|
||||
this.onUpgrade(body);
|
||||
} else if (ret === constants3.ERROR.PAUSED) {
|
||||
this.paused = true;
|
||||
socket.unshift(body);
|
||||
} else {
|
||||
throw this.createError(ret, body);
|
||||
}
|
||||
throw new HTTPParserError(message, constants3.ERROR[ret], data.slice(offset));
|
||||
}
|
||||
} catch (err) {
|
||||
util.destroy(socket, err);
|
||||
}
|
||||
}
|
||||
finish() {
|
||||
assert(currentParser === null);
|
||||
assert(this.ptr != null);
|
||||
assert(!this.paused);
|
||||
const { llhttp } = this;
|
||||
let ret;
|
||||
try {
|
||||
currentParser = this;
|
||||
ret = llhttp.llhttp_finish(this.ptr);
|
||||
} finally {
|
||||
currentParser = null;
|
||||
}
|
||||
if (ret === constants3.ERROR.OK) {
|
||||
return null;
|
||||
}
|
||||
if (ret === constants3.ERROR.PAUSED || ret === constants3.ERROR.PAUSED_UPGRADE) {
|
||||
this.paused = true;
|
||||
return null;
|
||||
}
|
||||
return this.createError(ret, EMPTY_BUF);
|
||||
}
|
||||
createError(ret, data) {
|
||||
const { llhttp, contentLength, bytesRead } = this;
|
||||
if (contentLength && bytesRead !== parseInt(contentLength, 10)) {
|
||||
return new ResponseContentLengthMismatchError();
|
||||
}
|
||||
const ptr = llhttp.llhttp_get_error_reason(this.ptr);
|
||||
let message = "";
|
||||
if (ptr) {
|
||||
const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0);
|
||||
message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")";
|
||||
}
|
||||
return new HTTPParserError(message, constants3.ERROR[ret], data);
|
||||
}
|
||||
destroy() {
|
||||
assert(this.ptr != null);
|
||||
assert(currentParser == null);
|
||||
@@ -5899,6 +5945,10 @@ var require_client_h1 = __commonJS({
|
||||
if (socket.destroyed) {
|
||||
return -1;
|
||||
}
|
||||
if (client[kRunning] === 0) {
|
||||
util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
|
||||
return -1;
|
||||
}
|
||||
const request = client[kQueue][client[kRunningIdx]];
|
||||
if (!request) {
|
||||
return -1;
|
||||
@@ -5978,6 +6028,10 @@ var require_client_h1 = __commonJS({
|
||||
if (socket.destroyed) {
|
||||
return -1;
|
||||
}
|
||||
if (client[kRunning] === 0) {
|
||||
util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
|
||||
return -1;
|
||||
}
|
||||
const request = client[kQueue][client[kRunningIdx]];
|
||||
if (!request) {
|
||||
return -1;
|
||||
@@ -6103,6 +6157,7 @@ var require_client_h1 = __commonJS({
|
||||
}
|
||||
request.onComplete(headers);
|
||||
client[kQueue][client[kRunningIdx]++] = null;
|
||||
socket[kSocketUsed] = true;
|
||||
if (socket[kWriting]) {
|
||||
assert(client[kRunning] === 0);
|
||||
util.destroy(socket, new InformationalError("reset"));
|
||||
@@ -6146,12 +6201,19 @@ var require_client_h1 = __commonJS({
|
||||
socket[kWriting] = false;
|
||||
socket[kReset] = false;
|
||||
socket[kBlocking] = false;
|
||||
socket[kIdleSocketValidation] = 0;
|
||||
socket[kIdleSocketValidationTimeout] = null;
|
||||
socket[kSocketUsed] = false;
|
||||
socket[kParser] = new Parser(client, socket, llhttpInstance);
|
||||
addListener(socket, "error", function(err) {
|
||||
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
|
||||
const parser = this[kParser];
|
||||
if (err.code === "ECONNRESET" && parser.statusCode && !parser.shouldKeepAlive) {
|
||||
parser.onMessageComplete();
|
||||
const parserErr = parser.finish();
|
||||
if (parserErr) {
|
||||
this[kError] = parserErr;
|
||||
this[kClient][kOnError](parserErr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this[kError] = err;
|
||||
@@ -6166,7 +6228,10 @@ var require_client_h1 = __commonJS({
|
||||
addListener(socket, "end", function() {
|
||||
const parser = this[kParser];
|
||||
if (parser.statusCode && !parser.shouldKeepAlive) {
|
||||
parser.onMessageComplete();
|
||||
const parserErr = parser.finish();
|
||||
if (parserErr) {
|
||||
util.destroy(this, parserErr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
util.destroy(this, new SocketError("other side closed", util.getSocketInfo(this)));
|
||||
@@ -6174,9 +6239,10 @@ var require_client_h1 = __commonJS({
|
||||
addListener(socket, "close", function() {
|
||||
const client2 = this[kClient];
|
||||
const parser = this[kParser];
|
||||
clearIdleSocketValidation(this);
|
||||
if (parser) {
|
||||
if (!this[kError] && parser.statusCode && !parser.shouldKeepAlive) {
|
||||
parser.onMessageComplete();
|
||||
this[kError] = parser.finish() || this[kError];
|
||||
}
|
||||
this[kParser].destroy();
|
||||
this[kParser] = null;
|
||||
@@ -6225,7 +6291,7 @@ var require_client_h1 = __commonJS({
|
||||
return socket.destroyed;
|
||||
},
|
||||
busy(request) {
|
||||
if (socket[kWriting] || socket[kReset] || socket[kBlocking]) {
|
||||
if (socket[kWriting] || socket[kReset] || socket[kBlocking] || socket[kIdleSocketValidation] === 1) {
|
||||
return true;
|
||||
}
|
||||
if (request) {
|
||||
@@ -6243,6 +6309,24 @@ var require_client_h1 = __commonJS({
|
||||
}
|
||||
};
|
||||
}
|
||||
function clearIdleSocketValidation(socket) {
|
||||
if (socket[kIdleSocketValidationTimeout]) {
|
||||
clearTimeout(socket[kIdleSocketValidationTimeout]);
|
||||
socket[kIdleSocketValidationTimeout] = null;
|
||||
}
|
||||
socket[kIdleSocketValidation] = 0;
|
||||
}
|
||||
function scheduleIdleSocketValidation(client, socket) {
|
||||
socket[kIdleSocketValidation] = 1;
|
||||
socket[kIdleSocketValidationTimeout] = setTimeout(() => {
|
||||
socket[kIdleSocketValidationTimeout] = null;
|
||||
socket[kIdleSocketValidation] = 2;
|
||||
if (client[kSocket] === socket && !socket.destroyed) {
|
||||
client[kResume]();
|
||||
}
|
||||
}, 0);
|
||||
socket[kIdleSocketValidationTimeout].unref?.();
|
||||
}
|
||||
function resumeH1(client) {
|
||||
const socket = client[kSocket];
|
||||
if (socket && !socket.destroyed) {
|
||||
@@ -6255,6 +6339,29 @@ var require_client_h1 = __commonJS({
|
||||
socket.ref();
|
||||
socket[kNoRef] = false;
|
||||
}
|
||||
if (client[kRunning] === 0 && client[kPending] > 0 && socket[kSocketUsed]) {
|
||||
if (socket[kIdleSocketValidation] === 0) {
|
||||
scheduleIdleSocketValidation(client, socket);
|
||||
socket[kParser].readMore();
|
||||
if (socket.destroyed) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (socket[kIdleSocketValidation] === 1) {
|
||||
socket[kParser].readMore();
|
||||
if (socket.destroyed) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (client[kRunning] === 0) {
|
||||
socket[kParser].readMore();
|
||||
if (socket.destroyed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (client[kSize] === 0) {
|
||||
if (socket[kParser].timeoutType !== TIMEOUT_KEEP_ALIVE) {
|
||||
socket[kParser].setTimeout(client[kKeepAliveTimeoutValue], TIMEOUT_KEEP_ALIVE);
|
||||
@@ -6307,6 +6414,7 @@ var require_client_h1 = __commonJS({
|
||||
process.emitWarning(new RequestContentLengthMismatchError());
|
||||
}
|
||||
const socket = client[kSocket];
|
||||
clearIdleSocketValidation(socket);
|
||||
const abort = (err) => {
|
||||
if (request.aborted || request.completed) {
|
||||
return;
|
||||
@@ -7486,9 +7594,10 @@ var require_client = __commonJS({
|
||||
autoSelectFamilyAttemptTimeout,
|
||||
// h2
|
||||
maxConcurrentStreams,
|
||||
allowH2
|
||||
allowH2,
|
||||
webSocket
|
||||
} = {}) {
|
||||
super();
|
||||
super({ webSocket });
|
||||
if (keepAlive !== void 0) {
|
||||
throw new InvalidArgumentError("unsupported keepAlive, use pipelining=0 instead");
|
||||
}
|
||||
@@ -7994,8 +8103,8 @@ var require_pool_base = __commonJS({
|
||||
var kRemoveClient = /* @__PURE__ */ Symbol("remove client");
|
||||
var kStats = /* @__PURE__ */ Symbol("stats");
|
||||
var PoolBase = class extends DispatcherBase {
|
||||
constructor() {
|
||||
super();
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this[kQueue] = new FixedQueue();
|
||||
this[kClients] = [];
|
||||
this[kQueued] = 0;
|
||||
@@ -8166,7 +8275,6 @@ var require_pool = __commonJS({
|
||||
allowH2,
|
||||
...options
|
||||
} = {}) {
|
||||
super();
|
||||
if (connections != null && (!Number.isFinite(connections) || connections < 0)) {
|
||||
throw new InvalidArgumentError("invalid connections");
|
||||
}
|
||||
@@ -8187,6 +8295,7 @@ var require_pool = __commonJS({
|
||||
...connect
|
||||
});
|
||||
}
|
||||
super(options);
|
||||
this[kInterceptors] = options.interceptors?.Pool && Array.isArray(options.interceptors.Pool) ? options.interceptors.Pool : [];
|
||||
this[kConnections] = connections || null;
|
||||
this[kUrl] = util.parseOrigin(origin);
|
||||
@@ -8386,7 +8495,6 @@ var require_agent = __commonJS({
|
||||
}
|
||||
var Agent = class extends DispatcherBase {
|
||||
constructor({ factory = defaultFactory, maxRedirections = 0, connect, ...options } = {}) {
|
||||
super();
|
||||
if (typeof factory !== "function") {
|
||||
throw new InvalidArgumentError("factory must be a function.");
|
||||
}
|
||||
@@ -8396,6 +8504,7 @@ var require_agent = __commonJS({
|
||||
if (!Number.isInteger(maxRedirections) || maxRedirections < 0) {
|
||||
throw new InvalidArgumentError("maxRedirections must be a positive number");
|
||||
}
|
||||
super(options);
|
||||
if (connect && typeof connect !== "function") {
|
||||
connect = { ...connect };
|
||||
}
|
||||
@@ -16090,18 +16199,14 @@ var require_parse = __commonJS({
|
||||
} else if (attributeNameLowercase === "httponly") {
|
||||
cookieAttributeList.httpOnly = true;
|
||||
} else if (attributeNameLowercase === "samesite") {
|
||||
let enforcement = "Default";
|
||||
const attributeValueLowercase = attributeValue.toLowerCase();
|
||||
if (attributeValueLowercase.includes("none")) {
|
||||
enforcement = "None";
|
||||
if (attributeValueLowercase === "none") {
|
||||
cookieAttributeList.sameSite = "None";
|
||||
} else if (attributeValueLowercase === "strict") {
|
||||
cookieAttributeList.sameSite = "Strict";
|
||||
} else if (attributeValueLowercase === "lax") {
|
||||
cookieAttributeList.sameSite = "Lax";
|
||||
}
|
||||
if (attributeValueLowercase.includes("strict")) {
|
||||
enforcement = "Strict";
|
||||
}
|
||||
if (attributeValueLowercase.includes("lax")) {
|
||||
enforcement = "Lax";
|
||||
}
|
||||
cookieAttributeList.sameSite = enforcement;
|
||||
} else {
|
||||
cookieAttributeList.unparsed ??= [];
|
||||
cookieAttributeList.unparsed.push(`${attributeName}=${attributeValue}`);
|
||||
@@ -17029,27 +17134,26 @@ var require_permessage_deflate = __commonJS({
|
||||
var tail = Buffer.from([0, 0, 255, 255]);
|
||||
var kBuffer = /* @__PURE__ */ Symbol("kBuffer");
|
||||
var kLength = /* @__PURE__ */ Symbol("kLength");
|
||||
var kDefaultMaxDecompressedSize = 4 * 1024 * 1024;
|
||||
var PerMessageDeflate = class {
|
||||
/** @type {import('node:zlib').InflateRaw} */
|
||||
#inflate;
|
||||
#options = {};
|
||||
/** @type {boolean} */
|
||||
#aborted = false;
|
||||
/** @type {Function|null} */
|
||||
#currentCallback = null;
|
||||
#maxPayloadSize = 0;
|
||||
/**
|
||||
* @param {Map<string, string>} extensions
|
||||
*/
|
||||
constructor(extensions) {
|
||||
constructor(extensions, options) {
|
||||
this.#options.serverNoContextTakeover = extensions.has("server_no_context_takeover");
|
||||
this.#options.serverMaxWindowBits = extensions.get("server_max_window_bits");
|
||||
this.#maxPayloadSize = options.maxPayloadSize;
|
||||
}
|
||||
/**
|
||||
* Decompress a compressed payload.
|
||||
* @param {Buffer} chunk Compressed data
|
||||
* @param {boolean} fin Final fragment flag
|
||||
* @param {Function} callback Callback function
|
||||
*/
|
||||
decompress(chunk, fin, callback) {
|
||||
if (this.#aborted) {
|
||||
callback(new MessageSizeExceededError());
|
||||
return;
|
||||
}
|
||||
if (!this.#inflate) {
|
||||
let windowBits = Z_DEFAULT_WINDOWBITS;
|
||||
if (this.#options.serverMaxWindowBits) {
|
||||
@@ -17068,20 +17172,11 @@ var require_permessage_deflate = __commonJS({
|
||||
this.#inflate[kBuffer] = [];
|
||||
this.#inflate[kLength] = 0;
|
||||
this.#inflate.on("data", (data) => {
|
||||
if (this.#aborted) {
|
||||
return;
|
||||
}
|
||||
this.#inflate[kLength] += data.length;
|
||||
if (this.#inflate[kLength] > kDefaultMaxDecompressedSize) {
|
||||
this.#aborted = true;
|
||||
if (this.#maxPayloadSize > 0 && this.#inflate[kLength] > this.#maxPayloadSize) {
|
||||
callback(new MessageSizeExceededError());
|
||||
this.#inflate.removeAllListeners();
|
||||
this.#inflate.destroy();
|
||||
this.#inflate = null;
|
||||
if (this.#currentCallback) {
|
||||
const cb = this.#currentCallback;
|
||||
this.#currentCallback = null;
|
||||
cb(new MessageSizeExceededError());
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.#inflate[kBuffer].push(data);
|
||||
@@ -17091,19 +17186,17 @@ var require_permessage_deflate = __commonJS({
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
this.#currentCallback = callback;
|
||||
this.#inflate.write(chunk);
|
||||
if (fin) {
|
||||
this.#inflate.write(tail);
|
||||
}
|
||||
this.#inflate.flush(() => {
|
||||
if (this.#aborted || !this.#inflate) {
|
||||
if (!this.#inflate) {
|
||||
return;
|
||||
}
|
||||
const full = Buffer.concat(this.#inflate[kBuffer], this.#inflate[kLength]);
|
||||
this.#inflate[kBuffer].length = 0;
|
||||
this.#inflate[kLength] = 0;
|
||||
this.#currentCallback = null;
|
||||
callback(null, full);
|
||||
});
|
||||
}
|
||||
@@ -17134,8 +17227,14 @@ var require_receiver = __commonJS({
|
||||
var { WebsocketFrameSend } = require_frame();
|
||||
var { closeWebSocketConnection } = require_connection();
|
||||
var { PerMessageDeflate } = require_permessage_deflate();
|
||||
var { MessageSizeExceededError } = require_errors();
|
||||
function failWebsocketConnectionWithCode(ws, code, reason) {
|
||||
closeWebSocketConnection(ws, code, reason, Buffer.byteLength(reason));
|
||||
failWebsocketConnection(ws, reason);
|
||||
}
|
||||
var ByteParser = class extends Writable {
|
||||
#buffers = [];
|
||||
#fragmentsBytes = 0;
|
||||
#byteOffset = 0;
|
||||
#loop = false;
|
||||
#state = parserStates.INFO;
|
||||
@@ -17143,16 +17242,23 @@ var require_receiver = __commonJS({
|
||||
#fragments = [];
|
||||
/** @type {Map<string, PerMessageDeflate>} */
|
||||
#extensions;
|
||||
/** @type {number} */
|
||||
#maxFragments;
|
||||
/** @type {number} */
|
||||
#maxPayloadSize;
|
||||
/**
|
||||
* @param {import('./websocket').WebSocket} ws
|
||||
* @param {Map<string, string>|null} extensions
|
||||
* @param {{ maxFragments?: number, maxPayloadSize?: number }} [options]
|
||||
*/
|
||||
constructor(ws, extensions) {
|
||||
constructor(ws, extensions, options = {}) {
|
||||
super();
|
||||
this.ws = ws;
|
||||
this.#extensions = extensions == null ? /* @__PURE__ */ new Map() : extensions;
|
||||
this.#maxFragments = options.maxFragments ?? 0;
|
||||
this.#maxPayloadSize = options.maxPayloadSize ?? 0;
|
||||
if (this.#extensions.has("permessage-deflate")) {
|
||||
this.#extensions.set("permessage-deflate", new PerMessageDeflate(extensions));
|
||||
this.#extensions.set("permessage-deflate", new PerMessageDeflate(extensions, options));
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -17165,6 +17271,13 @@ var require_receiver = __commonJS({
|
||||
this.#loop = true;
|
||||
this.run(callback);
|
||||
}
|
||||
#validatePayloadLength() {
|
||||
if (this.#maxPayloadSize > 0 && !isControlFrame(this.#info.opcode) && this.#info.payloadLength + this.#fragmentsBytes > this.#maxPayloadSize) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1009, "Payload size exceeds maximum allowed size");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Runs whenever a new chunk is received.
|
||||
* Callback is called whenever there are no more chunks buffering,
|
||||
@@ -17224,6 +17337,9 @@ var require_receiver = __commonJS({
|
||||
if (payloadLength <= 125) {
|
||||
this.#info.payloadLength = payloadLength;
|
||||
this.#state = parserStates.READ_DATA;
|
||||
if (!this.#validatePayloadLength()) {
|
||||
return;
|
||||
}
|
||||
} else if (payloadLength === 126) {
|
||||
this.#state = parserStates.PAYLOADLENGTH_16;
|
||||
} else if (payloadLength === 127) {
|
||||
@@ -17244,6 +17360,9 @@ var require_receiver = __commonJS({
|
||||
const buffer = this.consume(2);
|
||||
this.#info.payloadLength = buffer.readUInt16BE(0);
|
||||
this.#state = parserStates.READ_DATA;
|
||||
if (!this.#validatePayloadLength()) {
|
||||
return;
|
||||
}
|
||||
} else if (this.#state === parserStates.PAYLOADLENGTH_64) {
|
||||
if (this.#byteOffset < 8) {
|
||||
return callback();
|
||||
@@ -17257,6 +17376,9 @@ var require_receiver = __commonJS({
|
||||
}
|
||||
this.#info.payloadLength = lower;
|
||||
this.#state = parserStates.READ_DATA;
|
||||
if (!this.#validatePayloadLength()) {
|
||||
return;
|
||||
}
|
||||
} else if (this.#state === parserStates.READ_DATA) {
|
||||
if (this.#byteOffset < this.#info.payloadLength) {
|
||||
return callback();
|
||||
@@ -17267,32 +17389,46 @@ var require_receiver = __commonJS({
|
||||
this.#state = parserStates.INFO;
|
||||
} else {
|
||||
if (!this.#info.compressed) {
|
||||
this.#fragments.push(body);
|
||||
if (!this.writeFragments(body)) {
|
||||
return;
|
||||
}
|
||||
if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1009, new MessageSizeExceededError().message);
|
||||
return;
|
||||
}
|
||||
if (!this.#info.fragmented && this.#info.fin) {
|
||||
const fullMessage = Buffer.concat(this.#fragments);
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, fullMessage);
|
||||
this.#fragments.length = 0;
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, this.consumeFragments());
|
||||
}
|
||||
this.#state = parserStates.INFO;
|
||||
} else {
|
||||
this.#extensions.get("permessage-deflate").decompress(body, this.#info.fin, (error2, data) => {
|
||||
if (error2) {
|
||||
failWebsocketConnection(this.ws, error2.message);
|
||||
return;
|
||||
}
|
||||
this.#fragments.push(data);
|
||||
if (!this.#info.fin) {
|
||||
this.#state = parserStates.INFO;
|
||||
this.#extensions.get("permessage-deflate").decompress(
|
||||
body,
|
||||
this.#info.fin,
|
||||
(error2, data) => {
|
||||
if (error2) {
|
||||
const code = error2 instanceof MessageSizeExceededError ? 1009 : 1007;
|
||||
failWebsocketConnectionWithCode(this.ws, code, error2.message);
|
||||
return;
|
||||
}
|
||||
if (!this.writeFragments(data)) {
|
||||
return;
|
||||
}
|
||||
if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1009, new MessageSizeExceededError().message);
|
||||
return;
|
||||
}
|
||||
if (!this.#info.fin) {
|
||||
this.#state = parserStates.INFO;
|
||||
this.#loop = true;
|
||||
this.run(callback);
|
||||
return;
|
||||
}
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, this.consumeFragments());
|
||||
this.#loop = true;
|
||||
this.#state = parserStates.INFO;
|
||||
this.run(callback);
|
||||
return;
|
||||
}
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, Buffer.concat(this.#fragments));
|
||||
this.#loop = true;
|
||||
this.#state = parserStates.INFO;
|
||||
this.#fragments.length = 0;
|
||||
this.run(callback);
|
||||
});
|
||||
);
|
||||
this.#loop = false;
|
||||
break;
|
||||
}
|
||||
@@ -17335,6 +17471,26 @@ var require_receiver = __commonJS({
|
||||
this.#byteOffset -= n;
|
||||
return buffer;
|
||||
}
|
||||
writeFragments(fragment) {
|
||||
if (this.#maxFragments > 0 && this.#fragments.length === this.#maxFragments) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1008, "Too many message fragments");
|
||||
return false;
|
||||
}
|
||||
this.#fragmentsBytes += fragment.length;
|
||||
this.#fragments.push(fragment);
|
||||
return true;
|
||||
}
|
||||
consumeFragments() {
|
||||
const fragments = this.#fragments;
|
||||
if (fragments.length === 1) {
|
||||
this.#fragmentsBytes = 0;
|
||||
return fragments.shift();
|
||||
}
|
||||
const output = Buffer.concat(fragments, this.#fragmentsBytes);
|
||||
this.#fragments = [];
|
||||
this.#fragmentsBytes = 0;
|
||||
return output;
|
||||
}
|
||||
parseCloseBody(data) {
|
||||
assert(data.length !== 1);
|
||||
let code;
|
||||
@@ -17772,7 +17928,13 @@ var require_websocket = __commonJS({
|
||||
*/
|
||||
#onConnectionEstablished(response, parsedExtensions) {
|
||||
this[kResponse] = response;
|
||||
const parser = new ByteParser(this, parsedExtensions);
|
||||
const webSocketOptions = this[kController]?.dispatcher?.webSocketOptions;
|
||||
const maxFragments = webSocketOptions?.maxFragments;
|
||||
const maxPayloadSize = webSocketOptions?.maxPayloadSize;
|
||||
const parser = new ByteParser(this, parsedExtensions, {
|
||||
maxFragments,
|
||||
maxPayloadSize
|
||||
});
|
||||
parser.on("drain", onParserDrain);
|
||||
parser.on("error", onParserError.bind(this));
|
||||
response.socket.ws = this;
|
||||
|
||||
Vendored
+315
-89
@@ -6,7 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
try {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
} catch (e) {
|
||||
throw mod = 0, e;
|
||||
}
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
@@ -2041,13 +2045,21 @@ var require_dispatcher_base = __commonJS({
|
||||
var kOnDestroyed = /* @__PURE__ */ Symbol("onDestroyed");
|
||||
var kOnClosed = /* @__PURE__ */ Symbol("onClosed");
|
||||
var kInterceptedDispatch = /* @__PURE__ */ Symbol("Intercepted Dispatch");
|
||||
var kWebSocketOptions = /* @__PURE__ */ Symbol("webSocketOptions");
|
||||
var DispatcherBase = class extends Dispatcher {
|
||||
constructor() {
|
||||
constructor(opts) {
|
||||
super();
|
||||
this[kDestroyed] = false;
|
||||
this[kOnDestroyed] = null;
|
||||
this[kClosed] = false;
|
||||
this[kOnClosed] = [];
|
||||
this[kWebSocketOptions] = opts?.webSocket ?? {};
|
||||
}
|
||||
get webSocketOptions() {
|
||||
return {
|
||||
maxFragments: this[kWebSocketOptions].maxFragments ?? 131072,
|
||||
maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? 128 * 1024 * 1024
|
||||
};
|
||||
}
|
||||
get destroyed() {
|
||||
return this[kDestroyed];
|
||||
@@ -5700,6 +5712,9 @@ var require_client_h1 = __commonJS({
|
||||
var FastBuffer = Buffer[Symbol.species];
|
||||
var addListener = util2.addListener;
|
||||
var removeAllListeners = util2.removeAllListeners;
|
||||
var kIdleSocketValidation = /* @__PURE__ */ Symbol("kIdleSocketValidation");
|
||||
var kIdleSocketValidationTimeout = /* @__PURE__ */ Symbol("kIdleSocketValidationTimeout");
|
||||
var kSocketUsed = /* @__PURE__ */ Symbol("kSocketUsed");
|
||||
var extractBody;
|
||||
async function lazyllhttp() {
|
||||
const llhttpWasmData = process.env.JEST_WORKER_ID ? require_llhttp_wasm() : void 0;
|
||||
@@ -5862,24 +5877,55 @@ var require_client_h1 = __commonJS({
|
||||
currentBufferRef = null;
|
||||
}
|
||||
const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr;
|
||||
if (ret === constants3.ERROR.PAUSED_UPGRADE) {
|
||||
this.onUpgrade(data.slice(offset));
|
||||
} else if (ret === constants3.ERROR.PAUSED) {
|
||||
this.paused = true;
|
||||
socket.unshift(data.slice(offset));
|
||||
} else if (ret !== constants3.ERROR.OK) {
|
||||
const ptr = llhttp.llhttp_get_error_reason(this.ptr);
|
||||
let message = "";
|
||||
if (ptr) {
|
||||
const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0);
|
||||
message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")";
|
||||
if (ret !== constants3.ERROR.OK) {
|
||||
const body = data.subarray(offset);
|
||||
if (ret === constants3.ERROR.PAUSED_UPGRADE) {
|
||||
this.onUpgrade(body);
|
||||
} else if (ret === constants3.ERROR.PAUSED) {
|
||||
this.paused = true;
|
||||
socket.unshift(body);
|
||||
} else {
|
||||
throw this.createError(ret, body);
|
||||
}
|
||||
throw new HTTPParserError(message, constants3.ERROR[ret], data.slice(offset));
|
||||
}
|
||||
} catch (err) {
|
||||
util2.destroy(socket, err);
|
||||
}
|
||||
}
|
||||
finish() {
|
||||
assert(currentParser === null);
|
||||
assert(this.ptr != null);
|
||||
assert(!this.paused);
|
||||
const { llhttp } = this;
|
||||
let ret;
|
||||
try {
|
||||
currentParser = this;
|
||||
ret = llhttp.llhttp_finish(this.ptr);
|
||||
} finally {
|
||||
currentParser = null;
|
||||
}
|
||||
if (ret === constants3.ERROR.OK) {
|
||||
return null;
|
||||
}
|
||||
if (ret === constants3.ERROR.PAUSED || ret === constants3.ERROR.PAUSED_UPGRADE) {
|
||||
this.paused = true;
|
||||
return null;
|
||||
}
|
||||
return this.createError(ret, EMPTY_BUF);
|
||||
}
|
||||
createError(ret, data) {
|
||||
const { llhttp, contentLength, bytesRead } = this;
|
||||
if (contentLength && bytesRead !== parseInt(contentLength, 10)) {
|
||||
return new ResponseContentLengthMismatchError();
|
||||
}
|
||||
const ptr = llhttp.llhttp_get_error_reason(this.ptr);
|
||||
let message = "";
|
||||
if (ptr) {
|
||||
const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0);
|
||||
message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")";
|
||||
}
|
||||
return new HTTPParserError(message, constants3.ERROR[ret], data);
|
||||
}
|
||||
destroy() {
|
||||
assert(this.ptr != null);
|
||||
assert(currentParser == null);
|
||||
@@ -5899,6 +5945,10 @@ var require_client_h1 = __commonJS({
|
||||
if (socket.destroyed) {
|
||||
return -1;
|
||||
}
|
||||
if (client[kRunning] === 0) {
|
||||
util2.destroy(socket, new SocketError("bad response", util2.getSocketInfo(socket)));
|
||||
return -1;
|
||||
}
|
||||
const request = client[kQueue][client[kRunningIdx]];
|
||||
if (!request) {
|
||||
return -1;
|
||||
@@ -5978,6 +6028,10 @@ var require_client_h1 = __commonJS({
|
||||
if (socket.destroyed) {
|
||||
return -1;
|
||||
}
|
||||
if (client[kRunning] === 0) {
|
||||
util2.destroy(socket, new SocketError("bad response", util2.getSocketInfo(socket)));
|
||||
return -1;
|
||||
}
|
||||
const request = client[kQueue][client[kRunningIdx]];
|
||||
if (!request) {
|
||||
return -1;
|
||||
@@ -6103,6 +6157,7 @@ var require_client_h1 = __commonJS({
|
||||
}
|
||||
request.onComplete(headers);
|
||||
client[kQueue][client[kRunningIdx]++] = null;
|
||||
socket[kSocketUsed] = true;
|
||||
if (socket[kWriting]) {
|
||||
assert(client[kRunning] === 0);
|
||||
util2.destroy(socket, new InformationalError("reset"));
|
||||
@@ -6146,12 +6201,19 @@ var require_client_h1 = __commonJS({
|
||||
socket[kWriting] = false;
|
||||
socket[kReset] = false;
|
||||
socket[kBlocking] = false;
|
||||
socket[kIdleSocketValidation] = 0;
|
||||
socket[kIdleSocketValidationTimeout] = null;
|
||||
socket[kSocketUsed] = false;
|
||||
socket[kParser] = new Parser(client, socket, llhttpInstance);
|
||||
addListener(socket, "error", function(err) {
|
||||
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
|
||||
const parser = this[kParser];
|
||||
if (err.code === "ECONNRESET" && parser.statusCode && !parser.shouldKeepAlive) {
|
||||
parser.onMessageComplete();
|
||||
const parserErr = parser.finish();
|
||||
if (parserErr) {
|
||||
this[kError] = parserErr;
|
||||
this[kClient][kOnError](parserErr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this[kError] = err;
|
||||
@@ -6166,7 +6228,10 @@ var require_client_h1 = __commonJS({
|
||||
addListener(socket, "end", function() {
|
||||
const parser = this[kParser];
|
||||
if (parser.statusCode && !parser.shouldKeepAlive) {
|
||||
parser.onMessageComplete();
|
||||
const parserErr = parser.finish();
|
||||
if (parserErr) {
|
||||
util2.destroy(this, parserErr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
util2.destroy(this, new SocketError("other side closed", util2.getSocketInfo(this)));
|
||||
@@ -6174,9 +6239,10 @@ var require_client_h1 = __commonJS({
|
||||
addListener(socket, "close", function() {
|
||||
const client2 = this[kClient];
|
||||
const parser = this[kParser];
|
||||
clearIdleSocketValidation(this);
|
||||
if (parser) {
|
||||
if (!this[kError] && parser.statusCode && !parser.shouldKeepAlive) {
|
||||
parser.onMessageComplete();
|
||||
this[kError] = parser.finish() || this[kError];
|
||||
}
|
||||
this[kParser].destroy();
|
||||
this[kParser] = null;
|
||||
@@ -6225,7 +6291,7 @@ var require_client_h1 = __commonJS({
|
||||
return socket.destroyed;
|
||||
},
|
||||
busy(request) {
|
||||
if (socket[kWriting] || socket[kReset] || socket[kBlocking]) {
|
||||
if (socket[kWriting] || socket[kReset] || socket[kBlocking] || socket[kIdleSocketValidation] === 1) {
|
||||
return true;
|
||||
}
|
||||
if (request) {
|
||||
@@ -6243,6 +6309,24 @@ var require_client_h1 = __commonJS({
|
||||
}
|
||||
};
|
||||
}
|
||||
function clearIdleSocketValidation(socket) {
|
||||
if (socket[kIdleSocketValidationTimeout]) {
|
||||
clearTimeout(socket[kIdleSocketValidationTimeout]);
|
||||
socket[kIdleSocketValidationTimeout] = null;
|
||||
}
|
||||
socket[kIdleSocketValidation] = 0;
|
||||
}
|
||||
function scheduleIdleSocketValidation(client, socket) {
|
||||
socket[kIdleSocketValidation] = 1;
|
||||
socket[kIdleSocketValidationTimeout] = setTimeout(() => {
|
||||
socket[kIdleSocketValidationTimeout] = null;
|
||||
socket[kIdleSocketValidation] = 2;
|
||||
if (client[kSocket] === socket && !socket.destroyed) {
|
||||
client[kResume]();
|
||||
}
|
||||
}, 0);
|
||||
socket[kIdleSocketValidationTimeout].unref?.();
|
||||
}
|
||||
function resumeH1(client) {
|
||||
const socket = client[kSocket];
|
||||
if (socket && !socket.destroyed) {
|
||||
@@ -6255,6 +6339,29 @@ var require_client_h1 = __commonJS({
|
||||
socket.ref();
|
||||
socket[kNoRef] = false;
|
||||
}
|
||||
if (client[kRunning] === 0 && client[kPending] > 0 && socket[kSocketUsed]) {
|
||||
if (socket[kIdleSocketValidation] === 0) {
|
||||
scheduleIdleSocketValidation(client, socket);
|
||||
socket[kParser].readMore();
|
||||
if (socket.destroyed) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (socket[kIdleSocketValidation] === 1) {
|
||||
socket[kParser].readMore();
|
||||
if (socket.destroyed) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (client[kRunning] === 0) {
|
||||
socket[kParser].readMore();
|
||||
if (socket.destroyed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (client[kSize] === 0) {
|
||||
if (socket[kParser].timeoutType !== TIMEOUT_KEEP_ALIVE) {
|
||||
socket[kParser].setTimeout(client[kKeepAliveTimeoutValue], TIMEOUT_KEEP_ALIVE);
|
||||
@@ -6307,6 +6414,7 @@ var require_client_h1 = __commonJS({
|
||||
process.emitWarning(new RequestContentLengthMismatchError());
|
||||
}
|
||||
const socket = client[kSocket];
|
||||
clearIdleSocketValidation(socket);
|
||||
const abort = (err) => {
|
||||
if (request.aborted || request.completed) {
|
||||
return;
|
||||
@@ -7486,9 +7594,10 @@ var require_client = __commonJS({
|
||||
autoSelectFamilyAttemptTimeout,
|
||||
// h2
|
||||
maxConcurrentStreams,
|
||||
allowH2
|
||||
allowH2,
|
||||
webSocket
|
||||
} = {}) {
|
||||
super();
|
||||
super({ webSocket });
|
||||
if (keepAlive !== void 0) {
|
||||
throw new InvalidArgumentError("unsupported keepAlive, use pipelining=0 instead");
|
||||
}
|
||||
@@ -7994,8 +8103,8 @@ var require_pool_base = __commonJS({
|
||||
var kRemoveClient = /* @__PURE__ */ Symbol("remove client");
|
||||
var kStats = /* @__PURE__ */ Symbol("stats");
|
||||
var PoolBase = class extends DispatcherBase {
|
||||
constructor() {
|
||||
super();
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this[kQueue] = new FixedQueue();
|
||||
this[kClients] = [];
|
||||
this[kQueued] = 0;
|
||||
@@ -8166,7 +8275,6 @@ var require_pool = __commonJS({
|
||||
allowH2,
|
||||
...options
|
||||
} = {}) {
|
||||
super();
|
||||
if (connections != null && (!Number.isFinite(connections) || connections < 0)) {
|
||||
throw new InvalidArgumentError("invalid connections");
|
||||
}
|
||||
@@ -8187,6 +8295,7 @@ var require_pool = __commonJS({
|
||||
...connect
|
||||
});
|
||||
}
|
||||
super(options);
|
||||
this[kInterceptors] = options.interceptors?.Pool && Array.isArray(options.interceptors.Pool) ? options.interceptors.Pool : [];
|
||||
this[kConnections] = connections || null;
|
||||
this[kUrl] = util2.parseOrigin(origin);
|
||||
@@ -8386,7 +8495,6 @@ var require_agent = __commonJS({
|
||||
}
|
||||
var Agent3 = class extends DispatcherBase {
|
||||
constructor({ factory = defaultFactory, maxRedirections = 0, connect, ...options } = {}) {
|
||||
super();
|
||||
if (typeof factory !== "function") {
|
||||
throw new InvalidArgumentError("factory must be a function.");
|
||||
}
|
||||
@@ -8396,6 +8504,7 @@ var require_agent = __commonJS({
|
||||
if (!Number.isInteger(maxRedirections) || maxRedirections < 0) {
|
||||
throw new InvalidArgumentError("maxRedirections must be a positive number");
|
||||
}
|
||||
super(options);
|
||||
if (connect && typeof connect !== "function") {
|
||||
connect = { ...connect };
|
||||
}
|
||||
@@ -16090,18 +16199,14 @@ var require_parse = __commonJS({
|
||||
} else if (attributeNameLowercase === "httponly") {
|
||||
cookieAttributeList.httpOnly = true;
|
||||
} else if (attributeNameLowercase === "samesite") {
|
||||
let enforcement = "Default";
|
||||
const attributeValueLowercase = attributeValue.toLowerCase();
|
||||
if (attributeValueLowercase.includes("none")) {
|
||||
enforcement = "None";
|
||||
if (attributeValueLowercase === "none") {
|
||||
cookieAttributeList.sameSite = "None";
|
||||
} else if (attributeValueLowercase === "strict") {
|
||||
cookieAttributeList.sameSite = "Strict";
|
||||
} else if (attributeValueLowercase === "lax") {
|
||||
cookieAttributeList.sameSite = "Lax";
|
||||
}
|
||||
if (attributeValueLowercase.includes("strict")) {
|
||||
enforcement = "Strict";
|
||||
}
|
||||
if (attributeValueLowercase.includes("lax")) {
|
||||
enforcement = "Lax";
|
||||
}
|
||||
cookieAttributeList.sameSite = enforcement;
|
||||
} else {
|
||||
cookieAttributeList.unparsed ??= [];
|
||||
cookieAttributeList.unparsed.push(`${attributeName}=${attributeValue}`);
|
||||
@@ -17029,27 +17134,26 @@ var require_permessage_deflate = __commonJS({
|
||||
var tail = Buffer.from([0, 0, 255, 255]);
|
||||
var kBuffer = /* @__PURE__ */ Symbol("kBuffer");
|
||||
var kLength = /* @__PURE__ */ Symbol("kLength");
|
||||
var kDefaultMaxDecompressedSize = 4 * 1024 * 1024;
|
||||
var PerMessageDeflate = class {
|
||||
/** @type {import('node:zlib').InflateRaw} */
|
||||
#inflate;
|
||||
#options = {};
|
||||
/** @type {boolean} */
|
||||
#aborted = false;
|
||||
/** @type {Function|null} */
|
||||
#currentCallback = null;
|
||||
#maxPayloadSize = 0;
|
||||
/**
|
||||
* @param {Map<string, string>} extensions
|
||||
*/
|
||||
constructor(extensions) {
|
||||
constructor(extensions, options) {
|
||||
this.#options.serverNoContextTakeover = extensions.has("server_no_context_takeover");
|
||||
this.#options.serverMaxWindowBits = extensions.get("server_max_window_bits");
|
||||
this.#maxPayloadSize = options.maxPayloadSize;
|
||||
}
|
||||
/**
|
||||
* Decompress a compressed payload.
|
||||
* @param {Buffer} chunk Compressed data
|
||||
* @param {boolean} fin Final fragment flag
|
||||
* @param {Function} callback Callback function
|
||||
*/
|
||||
decompress(chunk, fin, callback) {
|
||||
if (this.#aborted) {
|
||||
callback(new MessageSizeExceededError());
|
||||
return;
|
||||
}
|
||||
if (!this.#inflate) {
|
||||
let windowBits = Z_DEFAULT_WINDOWBITS;
|
||||
if (this.#options.serverMaxWindowBits) {
|
||||
@@ -17068,20 +17172,11 @@ var require_permessage_deflate = __commonJS({
|
||||
this.#inflate[kBuffer] = [];
|
||||
this.#inflate[kLength] = 0;
|
||||
this.#inflate.on("data", (data) => {
|
||||
if (this.#aborted) {
|
||||
return;
|
||||
}
|
||||
this.#inflate[kLength] += data.length;
|
||||
if (this.#inflate[kLength] > kDefaultMaxDecompressedSize) {
|
||||
this.#aborted = true;
|
||||
if (this.#maxPayloadSize > 0 && this.#inflate[kLength] > this.#maxPayloadSize) {
|
||||
callback(new MessageSizeExceededError());
|
||||
this.#inflate.removeAllListeners();
|
||||
this.#inflate.destroy();
|
||||
this.#inflate = null;
|
||||
if (this.#currentCallback) {
|
||||
const cb = this.#currentCallback;
|
||||
this.#currentCallback = null;
|
||||
cb(new MessageSizeExceededError());
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.#inflate[kBuffer].push(data);
|
||||
@@ -17091,19 +17186,17 @@ var require_permessage_deflate = __commonJS({
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
this.#currentCallback = callback;
|
||||
this.#inflate.write(chunk);
|
||||
if (fin) {
|
||||
this.#inflate.write(tail);
|
||||
}
|
||||
this.#inflate.flush(() => {
|
||||
if (this.#aborted || !this.#inflate) {
|
||||
if (!this.#inflate) {
|
||||
return;
|
||||
}
|
||||
const full = Buffer.concat(this.#inflate[kBuffer], this.#inflate[kLength]);
|
||||
this.#inflate[kBuffer].length = 0;
|
||||
this.#inflate[kLength] = 0;
|
||||
this.#currentCallback = null;
|
||||
callback(null, full);
|
||||
});
|
||||
}
|
||||
@@ -17134,8 +17227,14 @@ var require_receiver = __commonJS({
|
||||
var { WebsocketFrameSend } = require_frame();
|
||||
var { closeWebSocketConnection } = require_connection();
|
||||
var { PerMessageDeflate } = require_permessage_deflate();
|
||||
var { MessageSizeExceededError } = require_errors();
|
||||
function failWebsocketConnectionWithCode(ws, code, reason) {
|
||||
closeWebSocketConnection(ws, code, reason, Buffer.byteLength(reason));
|
||||
failWebsocketConnection(ws, reason);
|
||||
}
|
||||
var ByteParser = class extends Writable {
|
||||
#buffers = [];
|
||||
#fragmentsBytes = 0;
|
||||
#byteOffset = 0;
|
||||
#loop = false;
|
||||
#state = parserStates.INFO;
|
||||
@@ -17143,16 +17242,23 @@ var require_receiver = __commonJS({
|
||||
#fragments = [];
|
||||
/** @type {Map<string, PerMessageDeflate>} */
|
||||
#extensions;
|
||||
/** @type {number} */
|
||||
#maxFragments;
|
||||
/** @type {number} */
|
||||
#maxPayloadSize;
|
||||
/**
|
||||
* @param {import('./websocket').WebSocket} ws
|
||||
* @param {Map<string, string>|null} extensions
|
||||
* @param {{ maxFragments?: number, maxPayloadSize?: number }} [options]
|
||||
*/
|
||||
constructor(ws, extensions) {
|
||||
constructor(ws, extensions, options = {}) {
|
||||
super();
|
||||
this.ws = ws;
|
||||
this.#extensions = extensions == null ? /* @__PURE__ */ new Map() : extensions;
|
||||
this.#maxFragments = options.maxFragments ?? 0;
|
||||
this.#maxPayloadSize = options.maxPayloadSize ?? 0;
|
||||
if (this.#extensions.has("permessage-deflate")) {
|
||||
this.#extensions.set("permessage-deflate", new PerMessageDeflate(extensions));
|
||||
this.#extensions.set("permessage-deflate", new PerMessageDeflate(extensions, options));
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -17165,6 +17271,13 @@ var require_receiver = __commonJS({
|
||||
this.#loop = true;
|
||||
this.run(callback);
|
||||
}
|
||||
#validatePayloadLength() {
|
||||
if (this.#maxPayloadSize > 0 && !isControlFrame(this.#info.opcode) && this.#info.payloadLength + this.#fragmentsBytes > this.#maxPayloadSize) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1009, "Payload size exceeds maximum allowed size");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Runs whenever a new chunk is received.
|
||||
* Callback is called whenever there are no more chunks buffering,
|
||||
@@ -17224,6 +17337,9 @@ var require_receiver = __commonJS({
|
||||
if (payloadLength <= 125) {
|
||||
this.#info.payloadLength = payloadLength;
|
||||
this.#state = parserStates.READ_DATA;
|
||||
if (!this.#validatePayloadLength()) {
|
||||
return;
|
||||
}
|
||||
} else if (payloadLength === 126) {
|
||||
this.#state = parserStates.PAYLOADLENGTH_16;
|
||||
} else if (payloadLength === 127) {
|
||||
@@ -17244,6 +17360,9 @@ var require_receiver = __commonJS({
|
||||
const buffer = this.consume(2);
|
||||
this.#info.payloadLength = buffer.readUInt16BE(0);
|
||||
this.#state = parserStates.READ_DATA;
|
||||
if (!this.#validatePayloadLength()) {
|
||||
return;
|
||||
}
|
||||
} else if (this.#state === parserStates.PAYLOADLENGTH_64) {
|
||||
if (this.#byteOffset < 8) {
|
||||
return callback();
|
||||
@@ -17257,6 +17376,9 @@ var require_receiver = __commonJS({
|
||||
}
|
||||
this.#info.payloadLength = lower;
|
||||
this.#state = parserStates.READ_DATA;
|
||||
if (!this.#validatePayloadLength()) {
|
||||
return;
|
||||
}
|
||||
} else if (this.#state === parserStates.READ_DATA) {
|
||||
if (this.#byteOffset < this.#info.payloadLength) {
|
||||
return callback();
|
||||
@@ -17267,32 +17389,46 @@ var require_receiver = __commonJS({
|
||||
this.#state = parserStates.INFO;
|
||||
} else {
|
||||
if (!this.#info.compressed) {
|
||||
this.#fragments.push(body);
|
||||
if (!this.writeFragments(body)) {
|
||||
return;
|
||||
}
|
||||
if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1009, new MessageSizeExceededError().message);
|
||||
return;
|
||||
}
|
||||
if (!this.#info.fragmented && this.#info.fin) {
|
||||
const fullMessage = Buffer.concat(this.#fragments);
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, fullMessage);
|
||||
this.#fragments.length = 0;
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, this.consumeFragments());
|
||||
}
|
||||
this.#state = parserStates.INFO;
|
||||
} else {
|
||||
this.#extensions.get("permessage-deflate").decompress(body, this.#info.fin, (error2, data) => {
|
||||
if (error2) {
|
||||
failWebsocketConnection(this.ws, error2.message);
|
||||
return;
|
||||
}
|
||||
this.#fragments.push(data);
|
||||
if (!this.#info.fin) {
|
||||
this.#state = parserStates.INFO;
|
||||
this.#extensions.get("permessage-deflate").decompress(
|
||||
body,
|
||||
this.#info.fin,
|
||||
(error2, data) => {
|
||||
if (error2) {
|
||||
const code = error2 instanceof MessageSizeExceededError ? 1009 : 1007;
|
||||
failWebsocketConnectionWithCode(this.ws, code, error2.message);
|
||||
return;
|
||||
}
|
||||
if (!this.writeFragments(data)) {
|
||||
return;
|
||||
}
|
||||
if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1009, new MessageSizeExceededError().message);
|
||||
return;
|
||||
}
|
||||
if (!this.#info.fin) {
|
||||
this.#state = parserStates.INFO;
|
||||
this.#loop = true;
|
||||
this.run(callback);
|
||||
return;
|
||||
}
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, this.consumeFragments());
|
||||
this.#loop = true;
|
||||
this.#state = parserStates.INFO;
|
||||
this.run(callback);
|
||||
return;
|
||||
}
|
||||
websocketMessageReceived(this.ws, this.#info.binaryType, Buffer.concat(this.#fragments));
|
||||
this.#loop = true;
|
||||
this.#state = parserStates.INFO;
|
||||
this.#fragments.length = 0;
|
||||
this.run(callback);
|
||||
});
|
||||
);
|
||||
this.#loop = false;
|
||||
break;
|
||||
}
|
||||
@@ -17335,6 +17471,26 @@ var require_receiver = __commonJS({
|
||||
this.#byteOffset -= n;
|
||||
return buffer;
|
||||
}
|
||||
writeFragments(fragment) {
|
||||
if (this.#maxFragments > 0 && this.#fragments.length === this.#maxFragments) {
|
||||
failWebsocketConnectionWithCode(this.ws, 1008, "Too many message fragments");
|
||||
return false;
|
||||
}
|
||||
this.#fragmentsBytes += fragment.length;
|
||||
this.#fragments.push(fragment);
|
||||
return true;
|
||||
}
|
||||
consumeFragments() {
|
||||
const fragments = this.#fragments;
|
||||
if (fragments.length === 1) {
|
||||
this.#fragmentsBytes = 0;
|
||||
return fragments.shift();
|
||||
}
|
||||
const output = Buffer.concat(fragments, this.#fragmentsBytes);
|
||||
this.#fragments = [];
|
||||
this.#fragmentsBytes = 0;
|
||||
return output;
|
||||
}
|
||||
parseCloseBody(data) {
|
||||
assert(data.length !== 1);
|
||||
let code;
|
||||
@@ -17772,7 +17928,13 @@ var require_websocket = __commonJS({
|
||||
*/
|
||||
#onConnectionEstablished(response, parsedExtensions) {
|
||||
this[kResponse] = response;
|
||||
const parser = new ByteParser(this, parsedExtensions);
|
||||
const webSocketOptions = this[kController]?.dispatcher?.webSocketOptions;
|
||||
const maxFragments = webSocketOptions?.maxFragments;
|
||||
const maxPayloadSize = webSocketOptions?.maxPayloadSize;
|
||||
const parser = new ByteParser(this, parsedExtensions, {
|
||||
maxFragments,
|
||||
maxPayloadSize
|
||||
});
|
||||
parser.on("drain", onParserDrain);
|
||||
parser.on("error", onParserError.bind(this));
|
||||
response.socket.ws = this;
|
||||
@@ -18766,6 +18928,18 @@ var require_semver = __commonJS({
|
||||
var { safeRe: re, t } = require_re();
|
||||
var parseOptions = require_parse_options();
|
||||
var { compareIdentifiers } = require_identifiers();
|
||||
var isPrereleaseIdentifier = (prerelease, identifier) => {
|
||||
const identifiers = identifier.split(".");
|
||||
if (identifiers.length > prerelease.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < identifiers.length; i++) {
|
||||
if (compareIdentifiers(prerelease[i], identifiers[i]) !== 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var SemVer = class _SemVer {
|
||||
constructor(version, options) {
|
||||
options = parseOptions(options);
|
||||
@@ -19012,8 +19186,9 @@ var require_semver = __commonJS({
|
||||
if (identifierBase === false) {
|
||||
prerelease = [identifier];
|
||||
}
|
||||
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
||||
if (isNaN(this.prerelease[1])) {
|
||||
if (isPrereleaseIdentifier(this.prerelease, identifier)) {
|
||||
const prereleaseBase = this.prerelease[identifier.split(".").length];
|
||||
if (isNaN(prereleaseBase)) {
|
||||
this.prerelease = prerelease;
|
||||
}
|
||||
} else {
|
||||
@@ -19415,6 +19590,47 @@ var require_coerce = __commonJS({
|
||||
}
|
||||
});
|
||||
|
||||
// node_modules/semver/functions/truncate.js
|
||||
var require_truncate = __commonJS({
|
||||
"node_modules/semver/functions/truncate.js"(exports2, module2) {
|
||||
"use strict";
|
||||
var parse = require_parse2();
|
||||
var constants3 = require_constants6();
|
||||
var SemVer = require_semver();
|
||||
var truncate = (version, truncation, options) => {
|
||||
if (!constants3.RELEASE_TYPES.includes(truncation)) {
|
||||
return null;
|
||||
}
|
||||
const clonedVersion = cloneInputVersion(version, options);
|
||||
return clonedVersion && doTruncation(clonedVersion, truncation);
|
||||
};
|
||||
var cloneInputVersion = (version, options) => {
|
||||
const versionStringToParse = version instanceof SemVer ? version.version : version;
|
||||
return parse(versionStringToParse, options);
|
||||
};
|
||||
var doTruncation = (version, truncation) => {
|
||||
if (isPrerelease(truncation)) {
|
||||
return version.version;
|
||||
}
|
||||
version.prerelease = [];
|
||||
switch (truncation) {
|
||||
case "major":
|
||||
version.minor = 0;
|
||||
version.patch = 0;
|
||||
break;
|
||||
case "minor":
|
||||
version.patch = 0;
|
||||
break;
|
||||
}
|
||||
return version.format();
|
||||
};
|
||||
var isPrerelease = (type) => {
|
||||
return type.startsWith("pre");
|
||||
};
|
||||
module2.exports = truncate;
|
||||
}
|
||||
});
|
||||
|
||||
// node_modules/semver/internal/lrucache.js
|
||||
var require_lrucache = __commonJS({
|
||||
"node_modules/semver/internal/lrucache.js"(exports2, module2) {
|
||||
@@ -19523,6 +19739,7 @@ var require_range = __commonJS({
|
||||
return this.range;
|
||||
}
|
||||
parseRange(range2) {
|
||||
range2 = range2.replace(BUILDSTRIPRE, "");
|
||||
const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
|
||||
const memoKey = memoOpts + ":" + range2;
|
||||
const cached = cache.get(memoKey);
|
||||
@@ -19605,12 +19822,14 @@ var require_range = __commonJS({
|
||||
var SemVer = require_semver();
|
||||
var {
|
||||
safeRe: re,
|
||||
src,
|
||||
t,
|
||||
comparatorTrimReplace,
|
||||
tildeTrimReplace,
|
||||
caretTrimReplace
|
||||
} = require_re();
|
||||
var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants6();
|
||||
var BUILDSTRIPRE = new RegExp(src[t.BUILD], "g");
|
||||
var isNullSet = (c) => c.value === "<0.0.0-0";
|
||||
var isAny = (c) => c.value === "";
|
||||
var isSatisfiable = (comparators, options) => {
|
||||
@@ -19639,20 +19858,22 @@ var require_range = __commonJS({
|
||||
return comp;
|
||||
};
|
||||
var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
|
||||
var invalidXRangeOrder = (M, m, p) => isX(M) && !isX(m) || isX(m) && p && !isX(p);
|
||||
var replaceTildes = (comp, options) => {
|
||||
return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
|
||||
};
|
||||
var replaceTilde = (comp, options) => {
|
||||
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
||||
const z = options.includePrerelease ? "-0" : "";
|
||||
return comp.replace(r, (_, M, m, p, pr) => {
|
||||
debug2("tilde", comp, _, M, m, p, pr);
|
||||
let ret;
|
||||
if (isX(M)) {
|
||||
ret = "";
|
||||
} else if (isX(m)) {
|
||||
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
||||
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
||||
} else if (isX(p)) {
|
||||
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
||||
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
||||
} else if (pr) {
|
||||
debug2("replaceTilde pr", pr);
|
||||
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
||||
@@ -19698,9 +19919,9 @@ var require_range = __commonJS({
|
||||
debug2("no pr");
|
||||
if (M === "0") {
|
||||
if (m === "0") {
|
||||
ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
|
||||
ret = `>=${M}.${m}.${p} <${M}.${m}.${+p + 1}-0`;
|
||||
} else {
|
||||
ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
|
||||
ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
||||
}
|
||||
} else {
|
||||
ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
||||
@@ -19719,6 +19940,9 @@ var require_range = __commonJS({
|
||||
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
||||
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
||||
debug2("xRange", comp, ret, gtlt, M, m, p, pr);
|
||||
if (invalidXRangeOrder(M, m, p)) {
|
||||
return comp;
|
||||
}
|
||||
const xM = isX(M);
|
||||
const xm = xM || isX(m);
|
||||
const xp = xm || isX(p);
|
||||
@@ -20366,7 +20590,7 @@ var require_subset = __commonJS({
|
||||
if (higher === c && higher !== gt2) {
|
||||
return false;
|
||||
}
|
||||
} else if (gt2.operator === ">=" && !satisfies3(gt2.semver, String(c), options)) {
|
||||
} else if (gt2.operator === ">=" && !c.test(gt2.semver)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -20381,7 +20605,7 @@ var require_subset = __commonJS({
|
||||
if (lower === c && lower !== lt) {
|
||||
return false;
|
||||
}
|
||||
} else if (lt.operator === "<=" && !satisfies3(lt.semver, String(c), options)) {
|
||||
} else if (lt.operator === "<=" && !c.test(lt.semver)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -20449,6 +20673,7 @@ var require_semver2 = __commonJS({
|
||||
var lte2 = require_lte();
|
||||
var cmp = require_cmp();
|
||||
var coerce = require_coerce();
|
||||
var truncate = require_truncate();
|
||||
var Comparator = require_comparator();
|
||||
var Range = require_range();
|
||||
var satisfies3 = require_satisfies();
|
||||
@@ -20487,6 +20712,7 @@ var require_semver2 = __commonJS({
|
||||
lte: lte2,
|
||||
cmp,
|
||||
coerce,
|
||||
truncate,
|
||||
Comparator,
|
||||
Range,
|
||||
satisfies: satisfies3,
|
||||
@@ -23189,7 +23415,7 @@ function expand_(str, max, isTop) {
|
||||
}
|
||||
const pad = n.some(isPadded);
|
||||
N = [];
|
||||
for (let i = x; test(i, y); i += incr) {
|
||||
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
||||
let c;
|
||||
if (isAlphaSequence) {
|
||||
c = String.fromCharCode(i);
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@slawek/install-github-release",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@slawek/install-github-release",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "3.0.0",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@slawek/install-github-release",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "A GitHub Action and CLI tool to download and install binaries from GitHub releases",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Reference in New Issue
Block a user