Skip to content

Commit

Permalink
Expose agent in http and https client.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal authored and ry committed Jan 23, 2011
1 parent 7892918 commit 8d37f80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down
8 changes: 6 additions & 2 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down

0 comments on commit 8d37f80

Please sign in to comment.