mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Initial pass at https client
This commit is contained in:
39
lib/https.js
39
lib/https.js
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user