From 53541ae90cb552164a61b9bed45c79cc54599a32 Mon Sep 17 00:00:00 2001 From: Tera <1527149+Denoder@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:19:33 +0200 Subject: [PATCH] Update ws.incoming.ts --- src/proxy/passes/ws.incoming.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/proxy/passes/ws.incoming.ts b/src/proxy/passes/ws.incoming.ts index d86d871..5f907b0 100644 --- a/src/proxy/passes/ws.incoming.ts +++ b/src/proxy/passes/ws.incoming.ts @@ -98,10 +98,11 @@ export async function stream(req: IncomingMessage, socket: Socket, options: Serv // Error Handler proxyReq.on('error', onOutgoingError); - proxyReq.on('response', function (res: IncomingMessage) { + proxyReq.on('response', function (res) { // if upgrade event isn't going to happen, close the socket // IncomingMessage type also passes through the response event - if (!res.headers.upgrade && !socket.destroyed) { + // @ts-expect-error: res.upgrade doesn't exist in `IncomingMessage` + if (!res.upgrade && socket.readyState !== 'closed') { socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers)); res.pipe(socket).on('error', onOutgoingError) }