Skip to content

Emit http-proxy:outgoing:ws:error for errors after the upgrade header. #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/http-proxy/passes/ws-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,26 @@ var passes = exports;
common.setupOutgoing(options.ssl || {}, options, req)
);
// Error Handler
proxyReq.on('error', function(err){
var onProxyError = function(err){
var ev = 'http-proxy:outgoing:ws:';
// If no error listeners, so throw the error.
if (!options.ee.listeners(ev + 'error').length){
throw err;
}
// Also emit the error events
options.ee.emit(ev + 'error', err, req, socket, head);
});
};

proxyReq.on('error', onProxyError);

proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
common.setupSocket(proxySocket);

// http client removes the error handler from proxySocket (which
// redirected 'error' events from proxySocket to proxyReq) before emitting
// 'upgrade'. So we need to ask for it again.
proxySocket.on('error', onProxyError);

if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead);

socket.write('HTTP/1.1 101 Switching Protocols\r\n');
Expand Down