mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] handle error on incoming request as well and properly abort proxy if client request is aborted
This commit is contained in:
parent
d908e2ad61
commit
77a1cff9bc
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user