How to use the follow-redirects.http 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 unfoldingWord / translationCore / src / js / helpers / DownloadHelpers.js View on Github external
module.exports.read = (uri) => {
  let parsedUrl = url.parse(uri, false, true);
  let makeRequest = parsedUrl.protocol === 'https:' ? https.request.bind(https) : http.request.bind(http);
  let serverPort = parsedUrl.port ? parsedUrl.port : parsedUrl.protocol === 'https:' ? 443 : 80;
  let agent = parsedUrl.protocol === 'https:' ? httpsAgent : httpAgent;

  let options = {
    host: parsedUrl.host,
    path: parsedUrl.path,
    agent: agent,
    port: serverPort,
    method: 'GET',
    headers: { 'Content-Type': 'application/json' },
  };

  return new Promise((resolve, reject) => {
    let req = makeRequest(options, (response) => {
      let data = '';