How to use the request.head function in request

To help you get started, we’ve selected a few request 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 strongloop / microgateway / datastore / apim-pull.js View on Github external
opts.suffix + '$';
    var regex = new RegExp(regexp);
    var i;
    for (i = 0; i < indirFiles.length; i++) {
      var file = regex.exec(indirFiles[i]);
      if (file) {
        etag = new Buffer(file[1], 'base64').toString();
        break;
      }
    }

    if (etag) {
      try {
        var headOpts = JSON.parse(JSON.stringify(options)); // clone options
        headOpts.headers = { 'If-None-Match': etag };
        request.head(headOpts, function(err, res, body) {
          if (err) {
            logger.error(err);
            cb();
            // not fatal; continue
          } else if (res.statusCode === 304) {
            var filename = path.join(opts.outdir, indirFiles[i]);
            fs.copy(path.join(opts.indir, indirFiles[i]),
                    filename,
                    { preserveTimestamps: true },
                    function(err) {
                      if (err) {
                        throw (err);
                      }
                      var body = decryptData(fs.readFileSync(filename));
                      logger.info('Using cached copy of %s', indirFiles[i]);
                      var result = {
github AstroCB / AssumeZero-Bot / src / utils.js View on Github external
exports.sendFileFromUrl = (url, path = "../media/temp.jpg", message = "", threadId, api = gapi) => {
    request.head(url, (err, res, body) => {
        // Download file and pass to chat API
        const fullpath = `${__dirname}/${path}`;
        if (!err) {
            request(url).pipe(fs.createWriteStream(fullpath)).on('close', (err, data) => {
                if (!err) {
                    // Use API's official sendMessage here for callback functionality
                    exports.sendMessage({
                        "body": message,
                        "attachment": fs.createReadStream(fullpath)
                    }, threadId, (err, data) => {
                        // Delete downloaded propic
                        fs.unlink(fullpath);
                    });
                } else {
                    exports.sendMessage(message, threadId);
                }
github mozilla-b2g / mozilla-get-url / test / support / get_suite.js View on Github external
test('exists on http site', function(done) {
        request.head(this.rawURL, function(err, res) {
          assert(
            res.statusCode > 199 && res.statusCode < 300,
            'file exists on server http status: ' + res.statusCode
          );
          done(err);
        });
      });
    });
github mburakerman / dinstagram / main.js View on Github external
var download = function (uri, filename, callback) {
    request.head(uri, function (err, res, body) {
        //console.log('content-type:', res.headers['content-type']);
        request(uri).pipe(fs.createWriteStream(filename)).on('close', function () {
            callback();
            var fileSize = formatBytes(res.headers['content-length']);
            console.log("size: " + fileSize);
        });
    });
};
github lyrgard / ffbeEquip / tools / JP / parseItems.js View on Github external
var download = function(uri, filename, callback){
    request.head(uri, function(err, res, body){
        if (err || res.statusCode == 404) {
            console.log("!! unable to download image : " + uri);
        } else {
            request(uri).pipe(fs.createWriteStream(filename)).on('close', function() {
                fs.createReadStream(filename).pipe(new PNG({
                    filterType: 4
                }))
                .on('error', function() {
                    fs.unlinkSync(filename);
                    console.log("!! image : " + uri + " invalid");
                })
                .on('parsed', function() {
                    console.log("image : " + uri + " downloaded and valid");
                });
                
            });
github gee-community / ee-runner / index.js View on Github external
var downloadAsync = function(uri, filename, callback){
    request.head(uri, function(err, res, body){
      request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
    });
  };
github aessam / ikhbr-SmartArabicNewsAggregator / FileDownloadQueue.js View on Github external
function download(uri, filename, callback){
    if(uri.length>10 && !fs.existsSync(filename)) {
        request.head(uri, function(err, res, body){
			if(err){
				Logger.log("ERROR",{
		            "Filename":filename,
		            "URL": uri,
		            "Data":Date.now()
		        });
			}
            if(res.headers["location"]){
                addImageToDownloadQueue(res.headers["location"], filename);
            }
            if(res.statusCode===200){
                var serverType = res.headers['content-type'].toLowerCase();
                var fileNametype = mime.lookup(filename);
                if(serverType===fileNametype){
                    request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
                }else{
github platformio / platformio-atom-ide / lib / installer / helpers.js View on Github external
return new Promise(resolve => {
    request.head({
      url
    }, (err, response) => {
      if (err || response.statusCode !== 200 || !response.headers.hasOwnProperty('content-length')) {
        resolve(-1);
      }
      resolve(parseInt(response.headers['content-length']));
    });
  });
}
github mediathekview / mediathekviewweb / server / app.ts View on Github external
redis.hget('mvw:contentLengthCache', url, (err, result) => {
        if (result) {
          callback(result);
        } else {
          request.head(url, (error, response) => {
            let contentLength = -1;

            if (!!response && !!response.headers['content-length']) {
              contentLength = response.headers['content-length'];
            }

            callback(contentLength);
            redis.hset('mvw:contentLengthCache', url, contentLength.toString());
          });
        }
      });
    });