How to use the follow-redirects.http.get function in follow-redirects

To help you get started, we’ve selected a few follow-redirects examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jhekasoft / insteadman2 / src / lib / manager.js View on Github external
installGame(game, downloadStatusCallback, beginInstallationCallback, endInstallationCallback) {
        var tempGamePath = this.configurator.getTempGamePath();
        this.configurator.checkAndCreateDirectory(tempGamePath);
        var tempPartGameFilepath = tempGamePath + 'tmp_' + game.name + '.part';
        var tempGameFilepath = tempGamePath + path.basename(game.url);

        var url = game.url;
        var bar;
        var file = fs.createWriteStream(tempPartGameFilepath);
        var here = this;
        http.get(url, function (res) {
            console.log(res);
            var total = res.headers['content-length'] || 0;
            console.log('total: ' + total);
            // TODO: try res.headers['content-disposition'] for filename
            // tempGameFilepath = ;
            bar = statusBar.create({total: total})
                .on('render', function (stats) {
                    downloadStatusCallback(game, {
                        percents: stats.percentage,
                        totalSize: stats.totalSize,
                        currentSize: stats.currentSize,
                        speed: stats.speed
                    });
                });

            res.pipe(file);
github s6joui / MirrorOS / apps / mirroros.social / instagram_api.js View on Github external
this.getTag = function(tag,callback){
		var http = require('follow-redirects').http;
        var options = {
          host: 'www.instagram.com',
          path: "/explore/tags/"+tag+"/?__a=1"
        };

        http.get(options, function (http_res) {
            var data = "";
            http_res.on("data", function (chunk) {
                data += chunk;
            });
            http_res.on("end", function () {
				var json = JSON.parse(data);
				if(json.graphql.hashtag.edge_hashtag_to_media){
					if(json.graphql.hashtag.edge_hashtag_to_media.length>0){
						callback(tag,json.graphql.hashtag.edge_hashtag_to_media.edges);
					}else if(json.graphql.hashtag.edge_hashtag_to_top_posts){
						callback(tag,json.graphql.hashtag.edge_hashtag_to_top_posts.edges);
					}else{
						console.log("No data found");
						callback(tag,[]);
					}
				}
github sharvil / api-docs / src / resource.js View on Github external
return new Promise((resolve, reject) => {
            Http.get(url, response => {
              response.on('error', reject);

              var buffer = '';
              response.on('data', chunk => { buffer += chunk; });
              response.on('end', () => { resolve(buffer); });
            }).on('error', reject);
          }).then(result => {
            Mkdirp(Path.dirname(writeFilename));
github ElemeFE / element-helper / lib / resource.js View on Github external
return new Promise((resolve, reject) => {
      Http.get(url, response => {
        response.on('error', reject);
        let buffer = '';
        response.on('data', chunk => { buffer += chunk; });
        response.on('end', () => { resolve(buffer); });
      }).on('error', reject);
    }).then(result => {
      if (filename) {
github peeriodproject / core / src / core / net / ip / FreeGeoIp.js View on Github external
FreeGeoIp.prototype.obtainIP = function (callback) {
        var _this = this;
        var callbackCalled = false;
        var doCallback = function (err, ip) {
            if (!callbackCalled) {
                callbackCalled = true;
                callback(err, ip);
            }
        };

        http.get(this._url, function (res) {
            var body = '';

            if (res.statusCode === 200) {
                res.on('data', function (chunk) {
                    if (chunk) {
                        body += chunk.toString('utf8');
                    }
                }).on('end', function () {
                    try  {
                        var ip = JSON.parse(body)[_this._attribute];
                        if (net.isIP(ip)) {
                            doCallback(null, ip);
                        } else {
                            doCallback(new Error('FreeGeoIp: Got no valid IP.'), null);
                        }
                    } catch (err) {
github MaxGfeller / youtube-mp3 / index.js View on Github external
var pingItem = function(token, reqBody, cb) {
 if(reqBody.indexOf('info') !== 0) return cb('Fail from api: ' + reqBody);

 eval(reqBody);

 http.get(info.pf, function(res) {
  cb(null, token, info);
 }).on('error', function(e) {
   return cb(e.message);
 });
}
github embark-framework / embark / lib / utils / utils.js View on Github external
function checkIsAvailable(url, callback) {
  http.get(url, function (_res) {
    callback(true);
  }).on('error', function (_res) {
    callback(false);
  });
}
github MaxGfeller / youtube-mp3 / index.js View on Github external
var downloadFile = function(token, info, cb) {
  var timestamp = (new Date).getTime();

  var options = {
    path: downloadLink.replace('{0}', token).
      replace('{1}', info.h).
      replace('{2}', timestamp + '.' + _cc(token + timestamp)),
    host: host,
    agent: false
  };

  var req = http.get(options, function(res) {
    var writeFile = fs.createWriteStream(filename, {'flags': 'a'});
    res.on('data', function(chunk) {
      writeFile.write(chunk, encoding='binary');
    });

    res.on('end', function() {
      writeFile.end();
      cb(null);
    });
  }).on('error', function(e) {
    cb(e);
  });
}
github rdfjs / N3.js / spec / SpecTester.js View on Github external
fs.exists(localFile, function (exists) {
    if (exists) {
      fs.readFile(localFile, 'utf8', callback);
    }
    else {
      var request = http.get(url.resolve(self._manifest, filename));
      request.on('response', function (response) {
        response.pipe(fs.createWriteStream(localFile))
                .on('close', function () { self._fetch(filename, callback); });
      });
      request.on('error', callback);
    }
  });
};