Permalink
Browse files

added support for http proxy (thanks to dvv@github)

  • Loading branch information...
1 parent 3f576f8 commit 28d6960a6c235897f79178852e65f5fa9926e1e0 @jeromeetienne committed Mar 10, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 nmod
View
16 nmod
@@ -44,12 +44,21 @@ var utils = {
errorCb = errorCb || function(error){}
var url = require('url').parse(urlStr);
var protocol = url.protocol.substr(0, url.protocol.length-1);
- var data= "";
+ var data = "";
var options = {
host : url.hostname,
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)
var req = require(protocol).request(options, function(res) {
var contentLength = parseInt(res.headers["content-length"], 10)
@@ -561,8 +570,7 @@ var nmod = function(cmdline, cmdopts){
if( typeof pkgJson !== "undefined" ){
require('fs').writeFileSync(dstDirname+"/package.json", JSON.stringify(pkgJson), "binary")
}
-
-
+
/**
* to install dependancies
*/

0 comments on commit 28d6960

Please sign in to comment.