diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index f288d3e..71eae76 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -662,6 +662,21 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) } }; +// +// ### function close() +// Closes all sockets associated with the Agents +// belonging to this instance. +// +HttpProxy.prototype.close = function () { + [this.forward, this.target].forEach(function (proxy) { + if (proxy.agent) { + proxy.agent.sockets.forEach(function (socket) { + socket.end(); + }); + } + }); +}; + // // ### @private function _forwardRequest (req) // #### @req {ServerRequest} Incoming HTTP Request to proxy.