From 99e63ddf4d78938cdc880d37dd6e7a89be6c445f Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 11 Sep 2012 11:14:00 +0900 Subject: [PATCH 1/3] support proxy. --- lib/core/package.js | 14 ++++++++++++-- lib/core/source.js | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/core/package.js b/lib/core/package.js index 976f8165..90a474c2 100644 --- a/lib/core/package.js +++ b/lib/core/package.js @@ -180,6 +180,12 @@ Package.prototype.download = function () { var src = url.parse(this.assetUrl); var req = src.protocol === 'https:' ? https : http; + if (process.env.HTTP_PROXY) { + var proxy = url.parse(process.env.HTTP_PROXY); + proxy.path = this.assetUrl; + src = proxy; + } + tmp.dir(function (err, tmpPath) { req.get(src, function (res) { @@ -271,7 +277,11 @@ Package.prototype.cache = function () { return this.emit('cache'); } template('action', { name: 'caching', shizzle: this.gitUrl }).on('data', this.emit.bind(this, 'data')); - var cp = spawn('git', ['clone', this.gitUrl, this.path]); + var url = this.gitUrl; + if (process.env.HTTP_PROXY) { + url = url.replace(/^git:/, 'https:'); + } + var cp = spawn('git', ['clone', url, this.path]); cp.stderr.setEncoding('utf8'); cp.stderr.on('data', this.emit.bind(this, 'data')); cp.on('close', function (code) { @@ -391,4 +401,4 @@ Package.prototype.__defineGetter__('localPath', function () { return path.join(process.cwd(), config.directory, this.name); }); -module.exports = Package; \ No newline at end of file +module.exports = Package; diff --git a/lib/core/source.js b/lib/core/source.js index 15643194..f88b1ba8 100644 --- a/lib/core/source.js +++ b/lib/core/source.js @@ -11,6 +11,10 @@ var _ = require('underscore'); var endpoint = 'https://bower.herokuapp.com/packages'; +if (process.env.HTTP_PROXY) { + request = request.defaults({'proxy': process.env.HTTP_PROXY}); +} + exports.lookup = function (name, callback) { request.get(endpoint + '/' + encodeURIComponent(name), function (err, response, body) { if (err || response.statusCode !== 200) return callback(err || new Error(name + ' not found')); @@ -65,4 +69,4 @@ exports.all = function (callback) { request.get(endpoint, function (err, response, body) { callback(err, body && JSON.parse(body)); }); -}; \ No newline at end of file +}; From db5ec83abfa0307856efac36ee6d31f495b57d5d Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 11 Sep 2012 11:23:34 +0900 Subject: [PATCH 2/3] fix indent. --- lib/core/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/package.js b/lib/core/package.js index 90a474c2..a422d01d 100644 --- a/lib/core/package.js +++ b/lib/core/package.js @@ -183,7 +183,7 @@ Package.prototype.download = function () { if (process.env.HTTP_PROXY) { var proxy = url.parse(process.env.HTTP_PROXY); proxy.path = this.assetUrl; - src = proxy; + src = proxy; } tmp.dir(function (err, tmpPath) { From d07f1e9e52ddfbe3968ca46279e54887b5b5e9e7 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 14 Sep 2012 09:32:06 +0900 Subject: [PATCH 3/3] set to src directly. --- lib/core/package.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/core/package.js b/lib/core/package.js index a422d01d..d67fa399 100644 --- a/lib/core/package.js +++ b/lib/core/package.js @@ -181,9 +181,8 @@ Package.prototype.download = function () { var req = src.protocol === 'https:' ? https : http; if (process.env.HTTP_PROXY) { - var proxy = url.parse(process.env.HTTP_PROXY); - proxy.path = this.assetUrl; - src = proxy; + src = url.parse(process.env.HTTP_PROXY); + src.path = this.assetUrl; } tmp.dir(function (err, tmpPath) {