Skip to content

Commit

Permalink
Merge pull request #6 from gramakri/master
Browse files Browse the repository at this point in the history
agent.addRequest parameters have changed
  • Loading branch information
mikeal committed Nov 1, 2013
2 parents fdd0ba7 + 7abb63b commit 680d5d3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,33 @@ function TunnelingAgent(options) {
}
util.inherits(TunnelingAgent, events.EventEmitter)

TunnelingAgent.prototype.addRequest = function addRequest(req, host, port) {
TunnelingAgent.prototype.addRequest = function addRequest(req, options) {
var self = this

// Legacy API: addRequest(req, host, port, path)
if (typeof options === 'string') {
options = {
host: options,
port: arguments[2],
path: arguments[3]
};
}

if (self.sockets.length >= this.maxSockets) {
// We are over limit so we'll add it to the queue.
self.requests.push({host: host, port: port, request: req})
return
}

// If we are under maxSockets create a new one.
self.createSocket({host: host, port: port, request: req}, function(socket) {
self.createSocket({host: options.host, port: options.port, request: req}, function(socket) {
socket.on('free', onFree)
socket.on('close', onCloseOrRemove)
socket.on('agentRemove', onCloseOrRemove)
req.onSocket(socket)

function onFree() {
self.emit('free', socket, host, port)
self.emit('free', socket, options.host, options.port)
}

function onCloseOrRemove(err) {
Expand Down

0 comments on commit 680d5d3

Please sign in to comment.