Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 7 Examples of "forever-agent in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'forever-agent' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

module.exports = function(url, opts) {
	if (!opts) opts = {};

	var queued = [];
	var that = {};
	var max = opts.max || 10; // default max ~10 in queue
	var onplaylist;

	var agent = undefined;

	if (opts.agent !== false) agent = /^https/.test(url) ? new ForeverAgent.SSL() : new ForeverAgent();

	var readPlaylist = function(playlistUrl, callback) {
		var ts = [];
		request(playlistUrl, {agent:agent}, function(err, response) {
			if (response.statusCode !== 200) return callback();

			var body = response.body.toString().trim();

			body = body.split('\n').map(function(line) {
				if (line[0] === '#') return line;
				var url = resolveUrl(playlistUrl, line);
				var id = '/'+md5(line)+'.ts';
				ts.push({url:url, id:id});
				return id;
			}).join('\n')+'\n';
Agent.prototype.init = function init(url, options) {
    var self = this;

    self.state = {};
    self.options = options || {};

    self.options.host = url.host;
    self.options.protocol = url.protocol;
    self.options.port = url.protocol === 'http:' ? 80 : 443;

    self.requests = {};
    self.sockets = {};
    self.freeSockets = {};
    self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets;
    self.minSockets = self.options.minSockets || HttpsAgent.defaultMinSockets;
    self.on('free', function(socket, host, port) {
        var name = getConnectionName(host, port);

        if (self.requests[name] && self.requests[name].length) {
            self.requests[name].shift().onSocket(socket)
        } else if (self.sockets[name].length < self.minSockets) {
            if (!self.freeSockets[name]) self.freeSockets[name] = [];
            self.freeSockets[name].push(socket);

            // if an error happens while we don't use the socket anyway, meh, throw the socket away
            var onIdleError = function() {
                socket.destroy();
            };
            socket._onIdleError = onIdleError;
            //socket.on('error', onIdleError);
        } else {
if (suser._source.emailSearch === undefined) {suser._source.emailSearch = false;}
      if (suser._source.removeEnabled === undefined) {suser._source.removeEnabled = false;}
      if (Config.get("multiES", false)) {suser._source.createEnabled = false;}

      return done(null, suser._source, {ha1: Config.store2ha1(suser._source.passStore)});
    });
  },
  function (options, done) {
      //TODO:  Should check nonce here
      return done(null, true);
  }
));

// Node 0.12 won't need this
var foreverAgent    = new ForeverAgent({minSockets: 21, maxSockets: 20});
var foreverAgentSSL = new ForeverAgent.SSL({minSockets: 21, maxSockets: 20});


app.configure(function() {
  app.enable("jsonp callback");
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.locals.molochversion =  molochversion.version;
  app.locals.isIndex = false;
  app.locals.basePath = Config.basePath();
  app.locals.elasticBase = "http://" + (escInfo[0] === "localhost"?os.hostname():escInfo[0]) + ":" + escInfo[1];
  app.locals.fieldsMap = JSON.stringify(Config.getFieldsMap());
  app.locals.fieldsArr = Config.getFields().sort(function(a,b) {return (a.exp > b.exp?1:-1);});
  app.locals.allowUploads = Config.get("uploadCommand") !== undefined;
  app.locals.sendSession = Config.getObj("sendSession");

  app.use(express.favicon(__dirname + '/public/favicon.ico'));
var request = require('request');
var ForeverAgent = require('forever-agent');
var param = require('param');
var level = require('./level');

var GITHUB_USER = {client_id:param('github.client'), client_secret:param('github.secret')};
var GITHUB_URL = /^https:\/\/api.github.com/;
var HTTP_URL = /^http:/;
var AGENT_SSL = new ForeverAgent.SSL();

var githubRequest = request.defaults({
	qs: GITHUB_USER,
	agent: AGENT_SSL,
	timeout: 30000
});

var httpRequest = request.defaults({
	agent: new ForeverAgent()
});

var matchRequest = function(url) {
	if (GITHUB_URL.test(url)) return githubRequest;
	if (HTTP_URL.test(url)) return httpRequest;
	return request;
};
try {
        url = URL.parse(options.uri, true);
    } catch (e) {
        throw new Error('a `uri` must be valid!');
    }

    if(url.protocol === 'http:') {
        return new HttpAgent(options);
    }

    if (!(this instanceof Agent)) {
        return new Agent(options);
    }

    HttpsAgent.call(this, options);

    this.init(url, options);
}
function WrapForeverSSLAgent(opts) {
  ForeverSSLAgent.call(this, opts);
  var _addRequest = this.addRequest;
  this.addRequest = function (req, host, port) {
    req.useChunkedEncodingByDefault = false;
    _addRequest.call(this, req, host, port);
  };
}
inherits(WrapForeverSSLAgent, ForeverSSLAgent);
function WrapForeverAgent(opts) {
  ForeverAgent.call(this, opts);
  var _addRequest = this.addRequest;
  this.addRequest = function (req, host, port) {
    req.useChunkedEncodingByDefault = false;
    _addRequest.call(this, req, host, port);
  };
}
inherits(WrapForeverAgent, ForeverAgent);

Is your System Free of Underlying Vulnerabilities?
Find Out Now