diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index 66c75d5..ebdbe2a 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -96,22 +96,21 @@ var passes = exports; * * @api private */ - function stream(req, socket, server, head, clb) { + function stream(req, socket, options, server, head, clb) { common.setupSocket(socket); if (head && head.length) socket.unshift(head); - var proxyReq = (~['https:', 'wss:'].indexOf(server.options.target.protocol) ? https : http).request( - common.setupOutgoing(server.options.ssl || {}, server.options, req) + var proxyReq = (~['https:', 'wss:'].indexOf(options.target.protocol) ? https : http).request( + common.setupOutgoing(options.ssl || {}, options, req) ); // Error Handler proxyReq.on('error', function(err){ - if(server) { - server.emit('error', err); - } - else { + if (clb) { clb(err); + } else { + server.emit('error', err, req, res); } });