From 8d37f80f4b582a55d229521cce83670b60300ec0 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Sat, 22 Jan 2011 16:09:50 -0800 Subject: [PATCH] Expose agent in http and https client. --- lib/http.js | 13 +++++++++---- lib/https.js | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/http.js b/lib/http.js index 3232d8397f8..eb8beb1f2a5 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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); }; diff --git a/lib/https.js b/lib/https.js index 1b161e6a697..bd1af1f69ee 100644 --- a/lib/https.js +++ b/lib/https.js @@ -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); };