| 214 | return agent; |
| 215 | } |
| 216 | function TunnelingAgent(options) { |
| 217 | var self = this; |
| 218 | self.options = options || {}; |
| 219 | self.proxyOptions = self.options.proxy || {}; |
| 220 | self.maxSockets = self.options.maxSockets || http.Agent.defaultMaxSockets; |
| 221 | self.requests = []; |
| 222 | self.sockets = []; |
| 223 | self.on("free", function onFree(socket, host, port, localAddress) { |
| 224 | var options2 = toOptions(host, port, localAddress); |
| 225 | for (var i = 0, len = self.requests.length; i < len; ++i) { |
| 226 | var pending = self.requests[i]; |
| 227 | if (pending.host === options2.host && pending.port === options2.port) { |
| 228 | self.requests.splice(i, 1); |
| 229 | pending.request.onSocket(socket); |
| 230 | return; |
| 231 | } |
| 232 | } |
| 233 | socket.destroy(); |
| 234 | self.removeSocket(socket); |
| 235 | }); |
| 236 | } |
| 237 | util.inherits(TunnelingAgent, events2.EventEmitter); |
| 238 | TunnelingAgent.prototype.addRequest = function addRequest(req, host, port, localAddress) { |
| 239 | var self = this; |