Skip to content

Commit

Permalink
fix: port http-party#1542
Browse files Browse the repository at this point in the history
  • Loading branch information
BerndSchrooten committed Jun 8, 2022
1 parent 080e129 commit 6293b3f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/http-proxy/passes/web-incoming.js
Expand Up @@ -154,7 +154,7 @@ module.exports = {

function createErrorHandler(proxyReq, url) {
return function proxyError(err) {
if (req.socket.destroyed && err.code === 'ECONNRESET') {
if (req.aborted && err.code === 'ECONNRESET') {
server.emit('econnreset', err, req, res, url);
return proxyReq.abort();
}
Expand Down
50 changes: 50 additions & 0 deletions test/lib-http-proxy-passes-web-incoming-test.js
Expand Up @@ -334,6 +334,56 @@ describe('#createProxyServer.web() using own http server', function () {
req.end();
});

it('should proxy the request and handle client disconnect error', function(done) {
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:45002',
});

require('net').createServer().listen(45002);

var proxyServer = http.createServer(requestHandler);

var cnt = 0;
var doneOne = function() {
cnt += 1;
if(cnt === 2) done();
}

var started = new Date().getTime();
function requestHandler(req, res) {
proxy.once('econnreset', function (err, errReq, errRes) {
proxyServer.close();
expect(err).to.be.an(Error);
expect(errReq).to.be.equal(req);
expect(errRes).to.be.equal(res);
expect(err.code).to.be('ECONNRESET');
doneOne();
});

proxy.web(req, res);
}

proxyServer.listen('8086');

var req = http.request({
hostname: '127.0.0.1',
port: '8086',
method: 'GET',
}, function() {});

req.on('error', function(err) {
expect(err).to.be.an(Error);
expect(err.code).to.be('ECONNRESET');
expect(new Date().getTime() - started).to.be.greaterThan(99);
doneOne();
});
req.end();

setTimeout(function () {
req.destroy();
}, 100);
});

it('should proxy the request and provide a proxyRes event with the request and response parameters', function(done) {
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:8080'
Expand Down

0 comments on commit 6293b3f

Please sign in to comment.