Skip to content

Commit

Permalink
[fix] handle error on incoming request as well and properly abort pro…
Browse files Browse the repository at this point in the history
…xy if client request is aborted
  • Loading branch information
jcrugzz committed Apr 14, 2014
1 parent d908e2a commit 77a1cff
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/http-proxy/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 77a1cff

Please sign in to comment.