Skip to content
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

Fix 'aborted' detection on Node v15.5.0+ #1559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/http-proxy/passes/web-incoming.js
Expand Up @@ -18,6 +18,11 @@ var nativeAgents = { http: httpNative, https: httpsNative };
* flexible.
*/

// 'aborted' event stopped working reliably on v15.5.0 and was later removed entirely
var supportsAbortedEvent = (function () {
var ver = process.versions.node.split('.').map(Number);
return ver[0] <= 14 || ver[0] === 15 && ver[1] <= 4;
}());

module.exports = {

Expand Down Expand Up @@ -143,9 +148,18 @@ module.exports = {
}

// Ensure we abort proxy if request is aborted
req.on('aborted', function () {
proxyReq.abort();
});
if (supportsAbortedEvent) {
req.on('aborted', function () {
proxyReq.abort();
});
} else {
res.on('close', function () {
var aborted = !res.writableFinished;
if (aborted) {
proxyReq.abort();
}
});
}

// handle errors in proxy and incoming request, just like for forward proxy
var proxyError = createErrorHandler(proxyReq, options.target);
Expand Down