Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {