This commit is contained in:
2026-08-14 16:03:47 +01:00
parent fd53e3f4fb
commit dfdc3b2840
2463 changed files with 186456 additions and 111315 deletions
+74 -4
View File
@@ -2,7 +2,7 @@
import { createServer as createServerHTTP } from "http";
// src/listener.ts
import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
// src/request.ts
import { Http2ServerRequest } from "http2";
@@ -151,6 +151,17 @@ var requestPrototype = {
}
});
});
Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), {
value: function(depth, options, inspectFn) {
const props = {
method: this.method,
url: this.url,
headers: this.headers,
nativeRequest: this[requestCache]
};
return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
}
});
Object.setPrototypeOf(requestPrototype, Request.prototype);
var newRequest = (incoming, defaultHostname) => {
const req = Object.create(requestPrototype);
@@ -257,6 +268,17 @@ var Response2 = class _Response {
}
});
});
Object.defineProperty(Response2.prototype, Symbol.for("nodejs.util.inspect.custom"), {
value: function(depth, options, inspectFn) {
const props = {
status: this.status,
headers: this.headers,
ok: this.ok,
nativeResponse: this[responseCache]
};
return `Response (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
}
});
Object.setPrototypeOf(Response2, GlobalResponse);
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
@@ -337,6 +359,50 @@ if (typeof global.crypto === "undefined") {
// src/listener.ts
var outgoingEnded = Symbol("outgoingEnded");
var incomingDraining = Symbol("incomingDraining");
var DRAIN_TIMEOUT_MS = 500;
var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
var drainIncoming = (incoming) => {
const incomingWithDrainState = incoming;
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
return;
}
incomingWithDrainState[incomingDraining] = true;
if (incoming instanceof Http2ServerRequest2) {
try {
;
incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
} catch {
}
return;
}
let bytesRead = 0;
const cleanup = () => {
clearTimeout(timer);
incoming.off("data", onData);
incoming.off("end", cleanup);
incoming.off("error", cleanup);
};
const forceClose = () => {
cleanup();
const socket = incoming.socket;
if (socket && !socket.destroyed) {
socket.destroySoon();
}
};
const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
timer.unref?.();
const onData = (chunk) => {
bytesRead += chunk.length;
if (bytesRead > MAX_DRAIN_BYTES) {
forceClose();
}
};
incoming.on("data", onData);
incoming.on("end", cleanup);
incoming.on("error", cleanup);
incoming.resume();
};
var handleRequestError = () => new Response(null, {
status: 400
});
@@ -508,14 +574,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
setTimeout(() => {
if (!incomingEnded) {
setTimeout(() => {
incoming.destroy();
outgoing.destroy();
drainIncoming(incoming);
});
}
});
}
};
}
outgoing.on("finish", () => {
if (!incomingEnded) {
drainIncoming(incoming);
}
});
}
outgoing.on("close", () => {
const abortController = req[abortControllerKey];
@@ -530,7 +600,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
setTimeout(() => {
if (!incomingEnded) {
setTimeout(() => {
incoming.destroy();
drainIncoming(incoming);
});
}
});