From d0862aff0c693366dcb11649b6abe1d011268953 Mon Sep 17 00:00:00 2001 From: yawnt Date: Thu, 7 Nov 2013 19:13:09 +0100 Subject: [PATCH] [fix] merge #495, thanks @glasser --- lib/http-proxy.js | 2 +- lib/http-proxy/passes/ws-incoming.js | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/http-proxy.js b/lib/http-proxy.js index 9620b7050..bef543fe3 100644 --- a/lib/http-proxy.js +++ b/lib/http-proxy.js @@ -36,7 +36,7 @@ proxy.createProxyServer = proxy.createServer = function createProxyServer(option * `options.target and `options.forward` cannot be * both missing * } - */ + */ return new httpProxy.Server(options); }; diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index ebdbe2ab0..e51c397e5 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -106,15 +106,11 @@ var passes = exports; common.setupOutgoing(options.ssl || {}, options, req) ); // Error Handler - proxyReq.on('error', function(err){ - if (clb) { - clb(err); - } else { - server.emit('error', err, req, res); - } - }); + proxyReq.on('error', onError); proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) { + proxySocket.on('error', onError); + common.setupSocket(proxySocket); if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead); @@ -126,7 +122,15 @@ var passes = exports; proxySocket.pipe(socket).pipe(proxySocket); }); - proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT + return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT + + function onError(err) { + if (clb) { + clb(err); + } else { + server.emit('error', err, req, res); + } + } } ] // <--