This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

getAgent consistancy between https and http

  • Loading branch information...
mikeal authored and ry committed Apr 23, 2011
1 parent 0b3ecc0 commit 698b1dafbf2e1f2f7c9f9997231af8ce8cd42ba3
Showing with 10 additions and 5 deletions.
  1. +10 −5 lib/http.js
View
@@ -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;
@@ -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);
}

0 comments on commit 698b1da

Please sign in to comment.