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 pietercolpaert / ldfetch / lib / NodeHttpFetcher.js View on Github external
totalBytes += chunk.length;
        });
        //extracted chunks to be added to the array
        responseStream.on('data', function (chunk) {
          chunks.push(chunk);
        });
        res.on('error', function (error) {
          onResponse(error);
        });
        responseStream.on('end', function () {
          self.emit('downloaded', { url: url, totalBytes: totalBytes });
          onResponse(null, res, chunks.join(''));
        })
      };
    if (parsedUrl.protocol === 'https:') {
      activeRequest = https.request(settings, executionResponse);
    } else if (parsedUrl.protocol === 'http:') {
      activeRequest = http.request(settings, executionResponse);
    } else {
      console.error('WARNING: Only http or https supported. Not ' + parsedUrl.protocol);
      deferred.reject(url + ' not using a protocol we can handle');
    }
    if (activeRequest) {
      activeRequest.on('error', function (e) {
        deferred.reject(e.message);
      });
      activeRequest.end();
      // Mark the request as active
      self._active[requestId] = { request: activeRequest, result: deferred.promise };
      self._pending++;
    }
  }