diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index 0555e56..94b1849 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -135,18 +135,18 @@ ProxyServer.prototype.listen = function(port, hostname) { }; ProxyServer.prototype.close = function(callback) { + var self = this; if (this._server) { - // Wrap callback to nullify server after all open connections are closed. - var callback_wrapper = function() { - this._server = null; - - if (callback) { - callback(arguments); - } - }; - - this._server.close(callback_wrapper); + this._server.close(done); } + + // Wrap callback to nullify server after all open connections are closed. + function done() { + self._server = null; + if (callback) { + callback.apply(null, arguments); + } + }; }; ProxyServer.prototype.before = function(type, passName, callback) {