Expose agent in http and https client.
authorMikeal Rogers <mikeal.rogers@gmail.com>
Sun, 23 Jan 2011 00:09:50 +0000 (16:09 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Sun, 23 Jan 2011 20:02:43 +0000 (12:02 -0800)
lib/http.js
lib/https.js

index 3232d83..eb8beb1 100644 (file)
@@ -1174,16 +1174,21 @@ function getAgent(host, port) {
 exports.getAgent = getAgent;
 
 
-exports._requestFromAgent = function(agent, options, cb) {
-  var req = agent.appendMessage(options);
+exports._requestFromAgent = function(options, cb) {
+  var req = options.agent.appendMessage(options);
+  req.agent = options.agent;
   if (cb) req.once('response', cb);
   return req;
 };
 
 
 exports.request = function(options, cb) {
-  var agent = getAgent(options.host, options.port);
-  return exports._requestFromAgent(agent, options, cb);
+  if (options.agent === undefined) {
+    options.agent = getAgent(options.host, options.port);
+  } else if (options.agent === false) {
+    options.agent = new Agent(options.host, options.port);
+  }
+  return exports._requestFromAgent(options, cb);
 };
 
 
index 1b161e6..bd1af1f 100644 (file)
@@ -59,8 +59,12 @@ exports.getAgent = getAgent;
 
 
 exports.request = function(options, cb) {
-  var agent = getAgent(options);
-  return http._requestFromAgent(agent, options, cb);
+  if (options.agent === undefined) {
+    options.agent = getAgent(options);
+  } else if (options.agent === false) {
+    options.agent = new Agent(options);
+  }
+  return http._requestFromAgent(options, cb);
 };