Skip to content

Commit

Permalink
added support for http proxy (thanks to dvv@github)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeetienne committed Mar 10, 2011
1 parent 3f576f8 commit 28d6960
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions nmod
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ var utils = {
errorCb = errorCb || function(error){} errorCb = errorCb || function(error){}
var url = require('url').parse(urlStr); var url = require('url').parse(urlStr);
var protocol = url.protocol.substr(0, url.protocol.length-1); var protocol = url.protocol.substr(0, url.protocol.length-1);
var data= ""; var data = "";
var options = { var options = {
host : url.hostname, host : url.hostname,
port : (url.port|| {'http': 80, 'https': 443}[protocol]), port : (url.port|| {'http': 80, 'https': 443}[protocol]),
path : url.pathname path : url.pathname,
headers : {}
}; };
// handle http proxy - from Vladimir Dronnikov dvv@github
if(process.env[protocol+'_proxy']||process.env.http_proxy) {
var proxy = require('url').parse(process.env[protocol+'_proxy']||process.env.http_proxy);
options.headers.host = options.host;
options.port = proxy.port || 80;
options.host = proxy.hostname;
options.path = urlStr;
}
//console.log("fetching", urlStr) //console.log("fetching", urlStr)
var req = require(protocol).request(options, function(res) { var req = require(protocol).request(options, function(res) {
var contentLength = parseInt(res.headers["content-length"], 10) var contentLength = parseInt(res.headers["content-length"], 10)
Expand Down Expand Up @@ -561,8 +570,7 @@ var nmod = function(cmdline, cmdopts){
if( typeof pkgJson !== "undefined" ){ if( typeof pkgJson !== "undefined" ){
require('fs').writeFileSync(dstDirname+"/package.json", JSON.stringify(pkgJson), "binary") require('fs').writeFileSync(dstDirname+"/package.json", JSON.stringify(pkgJson), "binary")
} }



/** /**
* to install dependancies * to install dependancies
*/ */
Expand Down

0 comments on commit 28d6960

Please sign in to comment.