From d8c54063dc5961fa619f7c04fa2d225da9aa1439 Mon Sep 17 00:00:00 2001 From: indexzero Date: Wed, 9 Mar 2011 17:40:43 -0500 Subject: [PATCH] [minor doc] Update demo and small fix to node-http-proxy --- demo.js | 9 +++++---- lib/node-http-proxy.js | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/demo.js b/demo.js index 75b0ce0..7380a71 100644 --- a/demo.js +++ b/demo.js @@ -60,8 +60,9 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + // Http Proxy Server with Latency // httpProxy.createServer(function (req, res, proxy) { + var paused = proxy.pause(req); setTimeout(function() { - proxy.proxyRequest(9000, 'localhost'); + proxy.proxyRequest(req, res, 9000, 'localhost', paused); }, 200) }).listen(8002); util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline); @@ -80,11 +81,11 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + // // Http Server with proxyRequest Handler and Latency // +var standAloneProxy = new httpProxy.HttpProxy(); http.createServer(function (req, res) { - var proxy = new httpProxy.HttpProxy(req, res); - + var paused = standAloneProxy.pause(req); setTimeout(function() { - proxy.proxyRequest(9000, 'localhost'); + proxy.proxyRequest(req, res, 9000, 'localhost', paused); }, 200); }).listen(8004); util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta); diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index d4b5eab..f4146b6 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -114,6 +114,8 @@ exports.createServer = function () { var HttpProxy = exports.HttpProxy = function (options) { events.EventEmitter.call(this); + + options = options || {}; this.options = options; if (options.router) { @@ -184,7 +186,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, paused) { // always ignore the proxyTable if an explicit `port` and `host` // arguments are supplied to `proxyRequest`. // - if (this.proxyTable && !host) { location = this.proxyTable.getProxyLocation(req);