node-http-proxy
node-http-proxy copied to clipboard
Fix handling of client disconnect so that econnreset event is emitted instead of error
Fixes #1455
Thank you so much for this fix; this issue has been the bane of my life for weeks and your solution totally fixes it. Would love to see this merged ASAP so I don't have to keep on modifying my local http-proxy files.
Fix works great. I have been using it on my project. Would be awesome to see this merged in! Please.... :)
Looks like this project is dead, so in order to use this fix we just forked the project and made the 1 line change in this PR. It seems to work for us. Took about 30 mins, but better than manually editing that file in node_modules 🤦
As this project is dead, we had to apply this change with https://www.npmjs.com/package/patch-package, thanks for the solution @gsf4726
Monkey patching function for who don't want to use the patch-package.
function monkeyPatchHttpProxyLibrary() {
// https://github.com/http-party/node-http-proxy/pull/1542
const filePath = path.join(
__dirname,
'../node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js',
);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const patchedFileContent = fileContent.replace(
`if (req.socket.destroyed && err.code === 'ECONNRESET') {`,
`if (req.aborted && err.code === 'ECONNRESET') {`,
);
fs.writeFileSync(filePath, patchedFileContent, 'utf-8');
}