Initial pass at https client

This commit is contained in:
Ryan Dahl
2011-01-21 13:12:35 -08:00
parent 86e687086b
commit e65f6b4ce1
4 changed files with 112 additions and 10 deletions

View File

@@ -20,3 +20,42 @@ exports.Server = Server;
exports.createServer = function(opts, requestListener) {
return new Server(opts, requestListener);
};
// HTTPS agents.
var agents = {};
function Agent(options) {
http.Agent.call(this, options.host, options.port);
this.options = options;
}
inherits(Agent, http.Agent);
Agent.prototype._getConnection = function(host, port, cb) {
var s = tls.connect(port, host, this.options, function() {
// do other checks here?
if (cb) cb();
});
return s;
};
function getAgent(options) {
var id = options.host + ':' + options.port;
var agent = agents[id];
if (!agent) {
agent = agents[id] = new Agent(options);
}
return agent;
}
exports.request = function(options, cb) {
var agent = getAgent(options);
return http._requestFromAgent(agent, options, cb);
};