Skip to content

Commit

Permalink
Request will keep it's own agent pool so that it can expose a maxSock…
Browse files Browse the repository at this point in the history
…ets setting for easy pool sizing.
  • Loading branch information
mikeal committed Feb 4, 2011
1 parent a3c80f9 commit 55f22f9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ var toBase64 = function(str) {

var isUrl = /^https?:/;

var agents = {};
var getAgent = function (host, port) {
return agents[host+':'+port] || new Agent();
}

var Request = function (options) {
stream.Stream.call(this);
this.readable = true;
Expand Down Expand Up @@ -149,6 +154,11 @@ Request.prototype.request = function () {
throw new Error('Argument error, options.body.');
}
}

if (options.maxSockets) {
options.agent = getAgent(options.host, options.port);
options.agent.maxSockets = options.maxSockets;
}

options.req = http.request(options, function (response) {
if (setHost) delete options.headers.host;
Expand Down

0 comments on commit 55f22f9

Please sign in to comment.