Skip to content

Commit 0eae2a9

Browse files
committed
[api] Added new close() method which cleans up sockets from HttpProxy instances
1 parent ec03d72 commit 0eae2a9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/node-http-proxy/http-proxy.js

+15
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,21 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
662662
}
663663
};
664664

665+
//
666+
// ### function close()
667+
// Closes all sockets associated with the Agents
668+
// belonging to this instance.
669+
//
670+
HttpProxy.prototype.close = function () {
671+
[this.forward, this.target].forEach(function (proxy) {
672+
if (proxy.agent) {
673+
proxy.agent.sockets.forEach(function (socket) {
674+
socket.end();
675+
});
676+
}
677+
});
678+
};
679+
665680
//
666681
// ### @private function _forwardRequest (req)
667682
// #### @req {ServerRequest} Incoming HTTP Request to proxy.

0 commit comments

Comments
 (0)