From 8251296d7f5c472ec523316e905d678042b043d3 Mon Sep 17 00:00:00 2001 From: indexzero Date: Mon, 22 Nov 2010 00:09:51 -0500 Subject: [PATCH] [dist minor] Removed vendored pool. Changed all references of sys to util --- bin/node-http-proxy | 19 ++--- config.sample.json | 2 +- demo.js | 22 ++--- lib/node-http-proxy.js | 11 ++- lib/proxy-table.js | 2 +- package.json | 2 +- test/forward-proxy-test.js | 2 +- test/node-http-proxy-test.js | 2 +- test/proxy-table-test.js | 2 +- vendor/pool/README.md | 41 --------- vendor/pool/main.js | 157 ----------------------------------- vendor/pool/package.json | 14 ---- 12 files changed, 31 insertions(+), 245 deletions(-) delete mode 100644 vendor/pool/README.md delete mode 100644 vendor/pool/main.js delete mode 100644 vendor/pool/package.json diff --git a/bin/node-http-proxy b/bin/node-http-proxy index c369c74..efe36a8 100755 --- a/bin/node-http-proxy +++ b/bin/node-http-proxy @@ -2,8 +2,7 @@ var path = require('path'), fs = require('fs'), - eyes = require('eyes'), - sys = require('sys'), + util = require('util'), argv = require('optimist').argv, httpProxy = require('./../lib/node-http-proxy'); @@ -21,7 +20,7 @@ var help = [ ]; if (argv.h || argv.help || Object.keys(argv).length === 2) { - sys.puts(help.join('\n')); + util.puts(help.join('\n')); process.exit(0); } @@ -29,11 +28,6 @@ var location, config = {}, port = argv.port || 80, target = argv.target; -// -// Check to see if we should silence the logs -// -config.silent = argv.silent || false; - // // If we were passed a config, parse it // @@ -42,11 +36,16 @@ if (argv.config) { var data = fs.readFileSync(argv.config); config = JSON.parse(data.toString()); } catch (ex) { - sys.puts('Error starting node-http-proxy: ' + ex); + util.puts('Error starting node-http-proxy: ' + ex); process.exit(1); } } +// +// Check to see if we should silence the logs +// +config.silent = typeof argv.silent !== 'undefined' ? argv.silent : config.silent; + // // If we were passed a target, parse the url string // @@ -73,5 +72,5 @@ server.listen(port); // Notify that the server is started // if (!config.silent) { - sys.puts('node-http-proxy server now listening on port: ' + port); + util.puts('node-http-proxy server now listening on port: ' + port); } diff --git a/config.sample.json b/config.sample.json index dc68a52..8f15f88 100644 --- a/config.sample.json +++ b/config.sample.json @@ -1,5 +1,5 @@ { - "silent": true, + "silent": false, "router": { "localhost": "localhost:9000" }, diff --git a/demo.js b/demo.js index d04d024..75b0ce0 100644 --- a/demo.js +++ b/demo.js @@ -24,7 +24,7 @@ */ -var sys = require('sys'), +var util = require('util'), colors = require('colors') http = require('http'), httpProxy = require('./lib/node-http-proxy'); @@ -37,24 +37,24 @@ var welcome = '\ # # # # ##### ##### ##### # # ## # \n\ # # # # # # # # # # # # # \n\ # # # # # # # # #### # # # \n'; -sys.puts(welcome.rainbow.bold); +util.puts(welcome.rainbow.bold); // // Basic Http Proxy Server // httpProxy.createServer(9000, 'localhost').listen(8000); -sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); +util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); // // Http Proxy Server with Proxy Table // httpProxy.createServer({ router: { - '127.0.0.1': 'localhost:9000' + 'localhost': 'localhost:9000' } }).listen(8001); -sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with proxy table'.magenta.underline) +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with proxy table'.magenta.underline) // // Http Proxy Server with Latency @@ -64,7 +64,7 @@ httpProxy.createServer(function (req, res, proxy) { proxy.proxyRequest(9000, 'localhost'); }, 200) }).listen(8002); -sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline); +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline); // // @@ -75,7 +75,7 @@ httpProxy.createServer(9000, 'localhost', { host: 'localhost' } }).listen(8003); -sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8003 '.yellow + 'with forward proxy'.magenta.underline) +util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8003 '.yellow + 'with forward proxy'.magenta.underline) // // Http Server with proxyRequest Handler and Latency @@ -87,7 +87,7 @@ http.createServer(function (req, res) { proxy.proxyRequest(9000, 'localhost'); }, 200); }).listen(8004); -sys.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta); // // Target Http Server @@ -97,15 +97,15 @@ http.createServer(function (req, res) { res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9000); -sys.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); +util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow); // // Target Http Forwarding Server // http.createServer(function (req, res) { - sys.puts('Receiving forward for: ' + req.url) + util.puts('Receiving forward for: ' + req.url) res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9001); -sys.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow); +util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow); diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index 1fb53ee..7f51bf5 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -24,9 +24,8 @@ */ -var sys = require('sys'), +var util = require('util'), http = require('http'), - eyes = require('eyes'), events = require('events'), pool = require('pool'), ProxyTable = require('./proxy-table').ProxyTable, @@ -58,7 +57,7 @@ exports.createServer = function () { router = options.router; forward = options.forward; - silent = options.silent || true; + silent = typeof options.silent !== 'undefined' ? options.silent : true; if (router) { proxyTable = new ProxyTable(router, options.silent); @@ -70,7 +69,7 @@ exports.createServer = function () { var server = http.createServer(function (req, res) { function log (message) { if (!silent) { - sys.log(message); + util.log(message); } } @@ -78,9 +77,9 @@ exports.createServer = function () { log('Incoming HTTP request to: ' + req.headers.host + req.url); if (forward) { - var forward = new HttpProxy(req, res); + var forwardProxy = new HttpProxy(req, res); log('Forwarding HTTP request to: ' + forward.host + ':' + forward.port); - forward.forwardRequest(forward.port, forward.host); + forwardProxy.forwardRequest(forward.port, forward.host); } // If we were passed a callback to process the request diff --git a/lib/proxy-table.js b/lib/proxy-table.js index da01532..f089dcd 100644 --- a/lib/proxy-table.js +++ b/lib/proxy-table.js @@ -30,7 +30,7 @@ var util = require('util'), var ProxyTable = function (router, silent) { events.EventEmitter.call(this); - this.silent = silent || true; + this.silent = typeof silent !== 'undefined' ? silent : true; if (typeof router === 'object') { // If we are passed an object literal setup diff --git a/package.json b/package.json index b78b1e4..88bce9d 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "vows": ">= 0.5.2" }, "main": "./lib/node-http-proxy", - "bin": { "http-proxy": "./bin/node-http-proxy" }, + "bin": { "node-http-proxy": "./bin/node-http-proxy" }, "scripts": { "test": "vows test/*-test.js --spec" }, "engines": { "node": ">= 0.3.0" } } \ No newline at end of file diff --git a/test/forward-proxy-test.js b/test/forward-proxy-test.js index 9d3bfab..1db9b42 100644 --- a/test/forward-proxy-test.js +++ b/test/forward-proxy-test.js @@ -7,7 +7,7 @@ var fs = require('fs'), vows = require('vows'), - sys = require('sys'), + util = require('util'), path = require('path'), request = require('request'), assert = require('assert'), diff --git a/test/node-http-proxy-test.js b/test/node-http-proxy-test.js index 54878ba..43d5320 100644 --- a/test/node-http-proxy-test.js +++ b/test/node-http-proxy-test.js @@ -25,7 +25,7 @@ */ var vows = require('vows'), - sys = require('sys'), + util = require('util'), request = require('request'), assert = require('assert'), helpers = require('./helpers'), diff --git a/test/proxy-table-test.js b/test/proxy-table-test.js index 09e29ce..a9596ef 100644 --- a/test/proxy-table-test.js +++ b/test/proxy-table-test.js @@ -7,7 +7,7 @@ var fs = require('fs'), vows = require('vows'), - sys = require('sys'), + util = require('util'), path = require('path'), request = require('request'), assert = require('assert'), diff --git a/vendor/pool/README.md b/vendor/pool/README.md deleted file mode 100644 index 0ab4be7..0000000 --- a/vendor/pool/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Pool -- Simple HTTP client pooling - -## Install - -
-  npm install pool
-
- -## Super simple to use - -Pool has two core usage scenarios: creating a pool and creating a set of pools. Creating a pool is easy: - -
-  var pool = require('pool'),
-      sys = require('sys'),
-      local = pool.createPool('80', 'localhost');
-
-  client = local.request('GET', '/', function (request) {
-    // You can work with the request here just as you would as if it 
-    // was returned from http.createClient
-    request.on('end', function () {
-      sys.puts('Request ended');
-    });
-  });
-
- -Creating a set of pools can be accomplished using a PoolManager: - -
-  var pool = require('pool'),
-      manager = pool.createPoolManager(),
-      local = manager.getPool('80', 'localhost');
-
-  client = local.request('GET', '/', function (request) {
-    // You can work with the request here just as you would as if it 
-    // was returned from http.createClient
-    request.on('end', function () {
-      sys.puts('Request ended');
-    });        
-  });
-
\ No newline at end of file diff --git a/vendor/pool/main.js b/vendor/pool/main.js deleted file mode 100644 index 30d9602..0000000 --- a/vendor/pool/main.js +++ /dev/null @@ -1,157 +0,0 @@ -var sys = require('sys') - , http = require('http') - , events = require('events') - ; - -function Pool (port, host, https, credentials) { - this.port = port; - this.host = host; - this.https = https; - this.credentials = credentials; - this.clients = []; - this.pending = []; - this.minClients = 0; - this.maxClients = 8; -}; - -sys.inherits(Pool, events.EventEmitter); - -Pool.prototype.getClient = function (cb) { - for (var i=0;i this.maxClients) { - this.clients[i].end(); - this.clients.splice(i, 1); - i-=1; - } else { - return cb(this.clients[i]); - } - } - } - if (this.clients.length >= this.maxClients) { - this.pending.push(cb); - } else { - var client = http.createClient(this.port, this.host, this.https, this.credentials); - this.clients.push(client); - cb(client); - } -}; - -Pool.prototype.request = function () { - // Argument parsing. This gets a little dicey with the - // differences in defaults - var method, url, headers, callback, args; - var self = this; - args = Array.prototype.slice.call(arguments); - - if (typeof args[args.length - 1] === 'function') { - callback = args.pop(); - } - if (args[0]) method = args[0]; - if (args[1]) url = args[1]; - if (args[2]) headers = args[2]; - - if (!headers) headers = {}; - if (!headers.Connection) headers.Connection = 'keep-alive'; - - self.getClient(function (client) { - var errorListener = function (error) { - client.removeListener("error", errorListener); - - // Remove the client from the available clients since it has errored - self.clients.splice(self.clients.indexOf(client), 1); - - self.emit("error", error); - request.emit("error", error); - }; - - var request = client.request(method, url, headers); - client.on("error", errorListener); - request.on("response", function (response) { - response.on("end", function () { - client.removeListener("error", errorListener); - client.busy = false; - self.onFree(client); - }) - }) - client.busy = true; - callback(request); - }); -}; - -Pool.prototype.onFree = function (client) { - if (this.pending.length > 0) this.pending.shift()(client); -}; - -Pool.prototype.getFree = function () { - return this.clients.filter(function (client) { return !client.busy }).length; -}; - -Pool.prototype.getBusy = function () { - return this.clients.filter(function (client) { return client.busy }).length; -}; - -Pool.prototype.setMinClients = function (num) { - this.minClients = num; - if (this.clients.length < num) { - for (var i=this.clients.length;i" -, "repository" : - { "type" : "git" - , "url" : "http://github.com/mikeal/node-utils.git" - } -, "bugs" : - { "web" : "http://github.com/mikeal/node-utils/issues" } -, "engines" : ["node >=0.1.90"] -, "main" : "./main" -}