http: http2 implementation
This commit is contained in:
parent
09ee29318f
commit
2b929c7f19
1038
lib/http.js
1038
lib/http.js
File diff suppressed because it is too large
Load Diff
42
lib/https.js
42
lib/https.js
@ -52,56 +52,28 @@ exports.createServer = function(opts, requestListener) {
|
|||||||
|
|
||||||
|
|
||||||
// HTTPS agents.
|
// HTTPS agents.
|
||||||
var agents = {};
|
|
||||||
|
|
||||||
function Agent(options) {
|
function Agent(options) {
|
||||||
http.Agent.call(this, options);
|
http.Agent.call(this, options);
|
||||||
|
this.createConnection = function(port, host) {
|
||||||
|
return tls.connect(port, host, options);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
inherits(Agent, http.Agent);
|
inherits(Agent, http.Agent);
|
||||||
|
|
||||||
|
|
||||||
Agent.prototype.defaultPort = 443;
|
Agent.prototype.defaultPort = 443;
|
||||||
|
|
||||||
|
var globalAgent = new Agent();
|
||||||
|
|
||||||
Agent.prototype._getConnection = function(options, cb) {
|
exports.globalAgent = globalAgent;
|
||||||
if (NPN_ENABLED && !this.options.NPNProtocols) {
|
|
||||||
this.options.NPNProtocols = ['http/1.1', 'http/1.0'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var s = tls.connect(options.port, options.host, this.options, function() {
|
|
||||||
// do other checks here?
|
|
||||||
if (cb) cb();
|
|
||||||
});
|
|
||||||
|
|
||||||
return s;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
function getAgent(options) {
|
|
||||||
if (!options.port) options.port = 443;
|
|
||||||
|
|
||||||
var id = options.host + ':' + options.port;
|
|
||||||
var agent = agents[id];
|
|
||||||
|
|
||||||
if (!agent) {
|
|
||||||
agent = agents[id] = new Agent(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return agent;
|
|
||||||
}
|
|
||||||
exports.getAgent = getAgent;
|
|
||||||
exports.Agent = Agent;
|
exports.Agent = Agent;
|
||||||
|
|
||||||
exports.request = function(options, cb) {
|
exports.request = function(options, cb) {
|
||||||
if (options.agent === undefined) {
|
if (options.agent === undefined) {
|
||||||
options.agent = getAgent(options);
|
options.agent = globalAgent;
|
||||||
} else if (options.agent === false) {
|
|
||||||
options.agent = new Agent(options);
|
|
||||||
}
|
}
|
||||||
return http._requestFromAgent(options, cb);
|
return http.request(options, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.get = function(options, cb) {
|
exports.get = function(options, cb) {
|
||||||
options.method = 'GET';
|
options.method = 'GET';
|
||||||
var req = exports.request(options, cb);
|
var req = exports.request(options, cb);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user