fix: land synology webhook bounded body reads (#25831) (thanks @bmendonca3)

This commit is contained in:
Peter Steinberger
2026-03-02 19:42:43 +00:00
parent 2b088ca125
commit a3bb7a5ee5
2 changed files with 14 additions and 1 deletions

View File

@@ -2,10 +2,22 @@ import { EventEmitter } from "node:events";
import type { IncomingMessage, ServerResponse } from "node:http";
export function makeReq(method: string, body: string): IncomingMessage {
const req = new EventEmitter() as IncomingMessage;
const req = new EventEmitter() as IncomingMessage & { destroyed: boolean };
req.method = method;
req.headers = {};
req.socket = { remoteAddress: "127.0.0.1" } as unknown as IncomingMessage["socket"];
req.destroyed = false;
req.destroy = ((_: Error | undefined) => {
if (req.destroyed) {
return req;
}
req.destroyed = true;
return req;
}) as IncomingMessage["destroy"];
process.nextTick(() => {
if (req.destroyed) {
return;
}
req.emit("data", Buffer.from(body));
req.emit("end");
});