Skip to content

Commit

Permalink
Update ws.incoming.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Denoder committed Jan 18, 2024
1 parent 1716cbc commit 53541ae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/proxy/passes/ws.incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 53541ae

Please sign in to comment.