How to use the follow-redirects.https.request 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 CodeDotJS / instavim / cli.js View on Github external
}
	});
}

// checking internet connection
checkInternet(isConnected => {
	if (isConnected) {
		console.log(colors.cyan.bold('\n ❱ Internet Connection   :    ✔\n'));
	} else {
		// stop the whole process if the network is unreachable
		console.log(colors.red.bold('\n ❱ Internet Connection   :    ✖\n'));
		process.exit(1);
	}
});

const req = https.request(options, res => {
	if (res.statusCode === 200) {
		console.log(colors.cyan.bold(' ❱ Valid Username        :    ✔'));

		setTimeout(() => {
			mkdirp(removeSlash, err => {
				if (err) {
					// optional
					console.log(colors.red.bold(boxen('Sorry! Couldn\'t create the desired directory')));
				} else {
					/* do nothing */
				}
			});
		}, 1500);
	} else {
		// stopping the whole process if the username is invalid
		console.log(colors.red.bold(' ❱ Valid Username        :    ✖\n'));
github neo4j-graphql / neo4j-graphql-cli / src / index.js View on Github external
} catch (e) {
      console.log(chalk.red.bold("Unable to read " + schemaFilename + " - falling back to default movieSchema.graphlql"));
      schema = config.DEFAULT_SCHEMA;
    }
  }

  var options = {
    headers: {
      'Authorization': "Basic " + new Buffer("neo4j:" + creds.password).toString('base64')
    },
    host: helpers.constructProxyIp(creds),
    path: '/graphql/idl',
    method: 'POST'
  }

  var req = https.request(options, (res) => {

    res.on('data', (chunk) => {
      // got some data
    });
    
    res.on('end', (d) => {
      //process.stdout.write(d);

      if (res.statusCode == 200) {
        return callback(null, creds)
      } else {
        return callback("Error, posting the schema IDL failed. Please ensure your schema format is valid.");
      }
      
    });
github jakemmarsh / node-soundcloud / lib / soundcloud.js View on Github external
hostname: data.uri,
      path: data.path + paramChar + qsdata,
      method: data.method
    };
    var req;
    var body;

    if ( data.method === 'POST' ) {
      options.path = data.path;
      options.headers = {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Content-Length': qsdata.length
      };
    }

    req = https.request(options, function (response) {
      body = '';
      response.on('data', function (chunk) {
        body += chunk;
      });
      response.on('end', function () {
        try {
          var d = JSON.parse(body);
          // See http://developers.soundcloud.com/docs/api/guide#errors for full list of error codes
          if ( Number(response.statusCode) >= 400 ) {
            callback(d.errors, d);
          } else {
            callback(undefined, d);
          }
        } catch (e) {
          callback(e);
        }
github CodeDotJS / image-of / new.js View on Github external
};

const folderName = './Image/';

mkdirp(folderName, err => {
	if (err) {
		console.error(err);

		process.exit(1);
	} else {
		console.log('Direcotry Created');
	}
});

if (argv.i) {
	const getUserID = https.request(userID, res => {
		if (res.statusCode === 200) {
			console.log('user found');
		} else {
			console.log('not done!');

			process.exit(1);
		}

		let storeData = '';

		res.setEncoding('utf8');

		res.on('data', d => {
			storeData += d;
		});
github neo4j-graphql / neo4j-graphql-cli / src / index.js View on Github external
function getAuthToken(callback) {
  console.log("Requesting token....");

  var options = {
    headers: {
      'x-api-key': config.API_KEY
    },
    host: config.API_URL,
    path: config.API_ENV + config.GET_AUTH_TOKEN_ENDPOINT,
    method: 'POST'
  }
  
  var req = https.request(options, (res) => {

    res.on('data', (d) => {
      var obj = JSON.parse(d);
      if (obj.status && obj.token) {
        callback(null, obj.token)
      } else {
        callback("Error, no auth token received");
      }
    });

  }).on('error', (e) => {
    callback(e);
  })

  req.write('{}');
  req.end();
github CodeDotJS / image-of / cli.js View on Github external
removeImage();
			spinner.stop();
			process.exit(1);
		}
	});
}

if (arg === '-u' || arg === '--user') {
	if (!inf) {
		logUpdate(`\n${pos} ${dim('To download image, please provide username of a facebook user!')} \n`);
		removeImage();
		process.exit(1);
	}
	showMessage();
	checkConnection();
	const getUserID = https.request(fetchEye, res => {
		if (res.statusCode === 200) {
			logUpdate();
			spinner.text = `${inf} is a facebook user!`;
		} else {
			logUpdate(`\n${pos} ${inf} ${dim('is not a facebook user!')}\n`);
			removeImage();
			process.exit(1);
		}

		let storeData = '';
		res.setEncoding('utf8');
		res.on('data', d => {
			storeData += d;
		});

		res.on('end', () => {
github CleverStack / cleverstack-cli / lib / install.js View on Github external
return new Promise(function(resolve) {
    var req = https.request(options, function(res) {
      res.setEncoding('utf-8');

      if (res.statusCode !== 200) {
        return resolve();
      }

      var responseString = '';

      res.on('data', function(data) {
        responseString += data;
      });

      res.on('end', function() {
        var body = JSON.parse(responseString);
        resolve(body);
      });
github linkedconnections / linked-connections-server / lib / manager / dataset_manager.js View on Github external
return new Promise((resolve, reject) => {
            const req = https.request(options, res => {
                try {
                    let file_name = new Date(res.headers['last-modified']).toISOString();
                    let path = this.storage + '/datasets/' + dataset.companyName + '/' + file_name + '.zip';

                    if (!fs.existsSync(path)) {
                        let wf = fs.createWriteStream(path, { encoding: 'base64' });

                        res.on('data', d => {
                            wf.write(d);
                        }).on('end', () => {
                            wf.end();
                            wf.on('finish', () => {
                                resolve(file_name);
                            });
                        });
                    } else {
github linkedconnections / linked-connections-server / lib / manager / gtfsrt2lc.js View on Github external
return new Promise((resolve, reject) => {
            if (url.protocol === 'https:') {
                let req = https.request(url, res => {
                    let encoding = res.headers['content-encoding']
                    let responseStream = res;
                    let buffer = false;

                    if (encoding && encoding == 'gzip') {
                        responseStream = res.pipe(zlib.createGunzip());
                    } else if (encoding && encoding == 'deflate') {
                        responseStream = res.pipe(zlib.createInflate())
                    }

                    responseStream.on('data', chunk => {
                        if (!buffer) {
                            buffer = chunk;
                        } else {
                            buffer = Buffer.concat([buffer, chunk], buffer.length + chunk.length);
                        }
github stef-levesque / vscode-shader / src / hlsl / hoverProvider.ts View on Github external
return new Promise((resolve, reject) => { 
            let request = https.request({
                host: uri.authority,
                path: uri.path,
                rejectUnauthorized: workspace.getConfiguration().get("http.proxyStrictSSL", true)
            }, (response) => {
                if (response.statusCode == 301 || response.statusCode == 302)
                    return resolve(response.headers.location);
                if (response.statusCode != 200)
                    return resolve(response.statusCode.toString());
                let html = '';
                response.on('data', (data) => { html += data.toString(); });
                response.on('end', () => { 
                    const dom = new JSDOM(html);
                    let topic = '';
                    let node = dom.window.document.querySelector('.content');
                    if (node) {
                        let num = node.getElementsByTagName('a').length;