// I'm sure this has already been done before...

var http = require('http');
var urlParse = require('url').parse;
var q = require('q');

function getUrl(url, headers) {
  var data = [];
  var d = q.defer();
  var options = urlParse(url);
  options.headers = headers;
  var request = http.get(options, function(response) {
    response.on('data', function(incoming) {
      data.push(incoming);
    });
    response.on('end', function() {
      d.resolve(data.join(''));
    });
  });

  request.on('error', function(e) {
    console.log(e + ' get url: ' + url);
    throw e;
  });
  return d.promise;
}

module.exports = {
  getUrl: getUrl
};

@@ -78,20 +78,21 @@
 %0Avar url
-Pars
+Modul
 e = requ
@@ -105,14 +105,8 @@
 rl')
-.parse
 ;%0Ava
@@ -158,16 +158,54 @@
 ders) %7B%0A
+  console.log('Getting url: ' + url);%0A
   var da
@@ -257,9 +257,16 @@
  url
-P
+Module.p
 arse
@@ -468,24 +468,239 @@
 unction() %7B%0A
+      if (response.statusCode == 302 %7C%7C response.statusCode == 301) %7B%0A        getUrl(urlModule.resolve(url, response.headers%5B'location'%5D), headers)%0A            .then(function(x) %7B d.resolve(x); %7D);%0A      %7D else %7B%0A  
       d.reso
@@ -719,16 +719,24 @@
 n(''));%0A
+      %7D%0A
     %7D);%0A

Support HTTP redirects