From 4c1a2c141630e86a014742f4eda4d319a825469a Mon Sep 17 00:00:00 2001 From: indexzero Date: Sat, 9 Mar 2013 02:21:31 -0500 Subject: [PATCH] [fix] Make options immutable in `RoutingProxy`. Fixes #248. --- lib/node-http-proxy/http-proxy.js | 2 +- lib/node-http-proxy/routing-proxy.js | 8 ++++---- package.json | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index ca1e64941..2528a02c4 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -101,7 +101,7 @@ var HttpProxy = exports.HttpProxy = function (options) { // be provided or the operation will fail with an `origin mismatch` // by definition. // - this.source = options.source || { host: 'localhost', port: 8000 }; + this.source = options.source || { host: 'localhost', port: 80 }; this.source.https = this.source.https || options.https; this.changeOrigin = options.changeOrigin || false; }; diff --git a/lib/node-http-proxy/routing-proxy.js b/lib/node-http-proxy/routing-proxy.js index 25026a27d..3216c824c 100644 --- a/lib/node-http-proxy/routing-proxy.js +++ b/lib/node-http-proxy/routing-proxy.js @@ -7,7 +7,7 @@ */ var events = require('events'), - util = require('util'), + utile = require('utile'), HttpProxy = require('./http-proxy').HttpProxy, ProxyTable = require('./proxy-table').ProxyTable; @@ -70,7 +70,7 @@ var RoutingProxy = exports.RoutingProxy = function (options) { // // Inherit from `events.EventEmitter`. // -util.inherits(RoutingProxy, events.EventEmitter); +utile.inherits(RoutingProxy, events.EventEmitter); // // ### function add (options) @@ -227,7 +227,7 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) { } if (!this.proxies[key]) { - this.add(options); + this.add(utile.clone(options)); } proxy = this.proxies[key]; @@ -267,7 +267,7 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti key = this._getKey(options); if (!this.proxies[key]) { - this.add(options); + this.add(utile.clone(options)); } proxy = this.proxies[key]; diff --git a/package.json b/package.json index 6f3653133..f169e2cd1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "dependencies": { "colors": "0.x.x", "optimist": "0.3.x", - "pkginfo": "0.2.x" + "pkginfo": "0.2.x", + "utile": "~0.1.7" }, "devDependencies": { "request": "1.9.x",