How to use forever-agent - 7 common examples

To help you get started, we’ve selected a few forever-agent 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 mafintosh / hls-buffer / index.js View on Github external
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';
github itteco / iframely / lib / agent.js View on Github external
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 {
github aol / moloch / viewer / viewer.js View on Github external
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'));
github mafintosh / node-modules / getJSON.js View on Github external
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;
};
github itteco / iframely / lib / agent.js View on Github external
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);
}
github elastic / elasticsearch-js / src / lib / connectors / _keep_alive_agent.js View on Github external
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);
github elastic / elasticsearch-js / src / lib / connectors / _keep_alive_agent.js View on Github external
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);

forever-agent

HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.

Apache-2.0
Latest version published 9 years ago

Package Health Score

74 / 100
Full package analysis

Similar packages