From 26537866b3ca522927aa4604a958f90774c0c0c0 Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 9 Dec 2014 06:53:42 +0100 Subject: [PATCH] [api] add close event in ws-incoming.js --- lib/http-proxy/passes/ws-incoming.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index 9ad8060..9e96fbd 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -96,6 +96,12 @@ var passes = exports; proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) { proxySocket.on('error', onOutgoingError); + + // Allow us to listen when the websocket has completed + proxySocket.on('end', function () { + server.emit('close', proxyRes, proxySocket, proxyHead); + }); + // The pipe below will end proxySocket if socket closes cleanly, but not // if it errors (eg, vanishes from the net and starts returning // EHOSTUNREACH). We need to do that explicitly.