Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
getAgent consistancy between https and http
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal authored and ry committed Apr 23, 2011
1 parent 0b3ecc0 commit 698b1da
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/http.js
Expand Up @@ -1405,13 +1405,18 @@ Agent.prototype._cycle = function() {
var agents = {};


function getAgent(host, port) {
port = port || 80;
var id = host + ':' + port;
function getAgent(options, port) {
// Handle prior API that isn't in line with https
if (typeof options === 'string') {
options = {host:options, port:port};
}
if (!options.port) options.port = 80;

var id = options.host + ':' + options.port;
var agent = agents[id];

if (!agent) {
agent = agents[id] = new Agent({ host: host, port: port });
agent = agents[id] = new Agent(options);
}

return agent;
Expand All @@ -1429,7 +1434,7 @@ exports._requestFromAgent = function(options, cb) {

exports.request = function(options, cb) {
if (options.agent === undefined) {
options.agent = getAgent(options.host, options.port);
options.agent = getAgent({host:options.host, port:options.port});
} else if (options.agent === false) {
options.agent = new Agent(options);
}
Expand Down

0 comments on commit 698b1da

Please sign in to comment.