diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js index 26f12c695..a528c3689 100644 --- a/lib/http-proxy/passes/web-incoming.js +++ b/lib/http-proxy/passes/web-incoming.js @@ -91,9 +91,7 @@ web_o = Object.keys(web_o).map(function(pass) { function stream(req, res, options, _, server, clb) { - // // And we begin! - // if (!clb) { server.emit('start', req, res, options.target) } @@ -111,14 +109,24 @@ web_o = Object.keys(web_o).map(function(pass) { common.setupOutgoing(options.ssl || {}, options, req) ); + // Ensure we abort proxy if request is aborted + req.on('aborted', function () { + proxyReq.abort(); + }); + + // Handle errors on incoming request as well as it makes sense to + req.on('error', proxyError); + // Error Handler - proxyReq.on('error', function(err){ + proxyReq.on('error', proxyError); + + function proxyError (err){ if (clb) { clb(err, req, res); } else { server.emit('error', err, req, res); } - }); + } (options.buffer || req).pipe(proxyReq); @@ -128,9 +136,7 @@ web_o = Object.keys(web_o).map(function(pass) { if(web_o[i](req, res, proxyRes)) { break; } } - // // Allow us to listen when the proxy has completed - // proxyRes.on('end', function () { if (!clb) { server.emit('end', req, res, proxyRes);