From 0eae2a913a2173d85478f8c9deec929388284ee2 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 8 Sep 2011 16:55:45 -0700 Subject: [PATCH] [api] Added new `close()` method which cleans up sockets from HttpProxy instances --- lib/node-http-proxy/http-proxy.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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.