How to use the follow-redirects.http.Agent 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 LinkedDataFragments / Client.js / lib / util / Request.js View on Github external
/*! @license MIT ©2016 Ruben Verborgh, Ghent University - imec */
/* Single-function HTTP(S) request module */

var EventEmitter = require('events').EventEmitter,
    _ = require('lodash'),
    url = require('url'),
    http = require('follow-redirects').http,
    https = require('follow-redirects').https,
    zlib = require('zlib');

// Try to keep connections open, and set a maximum number of connections per server
var AGENT_SETTINGS = { keepAlive: true, maxSockets: 5 };
var AGENTS = {
  http:  new http.Agent(AGENT_SETTINGS),
  https: new https.Agent(AGENT_SETTINGS),
};

// Decode encoded streams with these decoders
var DECODERS = { gzip: zlib.createGunzip, deflate: zlib.createInflate };

// Creates an HTTP request with the given settings
function createRequest(settings) {
  // Parse the request URL
  if (settings.url)
    _.assign(settings, url.parse(settings.url));

  // Emit the response through a proxy
  var request, requestProxy = new EventEmitter(),
      requester = settings.protocol === 'http:' ? http : https;
  settings.agents = AGENTS;