...
 
Commits (7)
node-forever-agent (0.6.1-1) unstable; urgency=medium
* Team upload
* New upstream version 0.6.1
* Use salsa.debian.org in Vcs-* fields
* Bump debhelper compatibility level to 11
* Bump Standards-Version to 4.2.1 (no changes needed)
* Change section to javascript, priority to optional
-- Pirate Praveen <praveen@debian.org> Tue, 18 Sep 2018 20:54:49 +0530
node-forever-agent (0.5.1-1) unstable; urgency=low
* Initial release (Closes: #719712)
......
Source: node-forever-agent
Section: web
Priority: extra
Section: javascript
Priority: optional
Maintainer: Debian Javascript Maintainers <pkg-javascript-devel@lists.alioth.debian.org>
Uploaders: Jérémy Lal <kapouer@melix.org>
Build-Depends:
debhelper (>= 8~)
, dh-buildinfo
Standards-Version: 3.9.4
debhelper (>= 11~)
, nodejs
Standards-Version: 4.2.1
Homepage: https://github.com/mikeal/forever-agent
Vcs-Git: git://anonscm.debian.org/collab-maint/node-forever-agent.git
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/node-forever-agent.git
Vcs-Git: https://salsa.debian.org/js-team/node-forever-agent.git
Vcs-Browser: https://salsa.debian.org/js-team/node-forever-agent
Package: node-forever-agent
Architecture: all
......
......@@ -7,6 +7,17 @@ var util = require('util')
, tls = require('tls')
, AgentSSL = require('https').Agent
function getConnectionName(host, port) {
var name = ''
if (typeof host === 'string') {
name = host + ':' + port
} else {
// For node.js v012.0 and iojs-v1.5.1, host is an object. And any existing localAddress is part of the connection name.
name = host.host + ':' + host.port + ':' + (host.localAddress ? (host.localAddress + ':') : ':')
}
return name
}
function ForeverAgent(options) {
var self = this
self.options = options || {}
......@@ -16,7 +27,8 @@ function ForeverAgent(options) {
self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets
self.minSockets = self.options.minSockets || ForeverAgent.defaultMinSockets
self.on('free', function(socket, host, port) {
var name = 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) {
......@@ -24,7 +36,7 @@ function ForeverAgent(options) {
self.freeSockets[name].push(socket)
// if an error happens while we don't use the socket anyway, meh, throw the socket away
function onIdleError() {
var onIdleError = function() {
socket.destroy()
}
socket._onIdleError = onIdleError
......@@ -47,7 +59,14 @@ ForeverAgent.defaultMinSockets = 5
ForeverAgent.prototype.createConnection = net.createConnection
ForeverAgent.prototype.addRequestNoreuse = Agent.prototype.addRequest
ForeverAgent.prototype.addRequest = function(req, host, port) {
var name = host + ':' + port
var name = getConnectionName(host, port)
if (typeof host !== 'string') {
var options = host
port = options.port
host = options.host
}
if (this.freeSockets[name] && this.freeSockets[name].length > 0 && !req.useChunkedEncodingByDefault) {
var idleSocket = this.freeSockets[name].pop()
idleSocket.removeListener('error', idleSocket._onIdleError)
......
......@@ -2,7 +2,8 @@
"author": "Mikeal Rogers <mikeal.rogers@gmail.com> (http://www.futurealoof.com)",
"name": "forever-agent",
"description": "HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.",
"version": "0.5.1",
"version": "0.6.1",
"license": "Apache-2.0",
"repository": {
"url": "https://github.com/mikeal/forever-agent"
},
......