https: refactor to use http internals
Rather than using `http`, use `_http_client`, etc. directly. Also moving all the exports to the bottom, in line with most of the rest of the codebase. PR-URL: https://github.com/nodejs/node/pull/16395 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
9ab648120c
commit
5118f31466
44
lib/https.js
44
lib/https.js
@ -25,8 +25,13 @@ require('internal/util').assertCrypto();
|
|||||||
|
|
||||||
const tls = require('tls');
|
const tls = require('tls');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const http = require('http');
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
const { Agent: HttpAgent } = require('_http_agent');
|
||||||
|
const {
|
||||||
|
Server: HttpServer,
|
||||||
|
_connectionListener
|
||||||
|
} = require('_http_server');
|
||||||
|
const { ClientRequest } = require('_http_client');
|
||||||
const { inherits } = util;
|
const { inherits } = util;
|
||||||
const debug = util.debuglog('https');
|
const debug = util.debuglog('https');
|
||||||
const { urlToOptions, searchParamsSymbol } = require('internal/url');
|
const { urlToOptions, searchParamsSymbol } = require('internal/url');
|
||||||
@ -52,7 +57,7 @@ function Server(opts, requestListener) {
|
|||||||
opts.ALPNProtocols = ['http/1.1'];
|
opts.ALPNProtocols = ['http/1.1'];
|
||||||
}
|
}
|
||||||
|
|
||||||
tls.Server.call(this, opts, http._connectionListener);
|
tls.Server.call(this, opts, _connectionListener);
|
||||||
|
|
||||||
this.httpAllowHalfOpen = false;
|
this.httpAllowHalfOpen = false;
|
||||||
|
|
||||||
@ -69,13 +74,12 @@ function Server(opts, requestListener) {
|
|||||||
this.keepAliveTimeout = 5000;
|
this.keepAliveTimeout = 5000;
|
||||||
}
|
}
|
||||||
inherits(Server, tls.Server);
|
inherits(Server, tls.Server);
|
||||||
exports.Server = Server;
|
|
||||||
|
|
||||||
Server.prototype.setTimeout = http.Server.prototype.setTimeout;
|
Server.prototype.setTimeout = HttpServer.prototype.setTimeout;
|
||||||
|
|
||||||
exports.createServer = function createServer(opts, requestListener) {
|
function createServer(opts, requestListener) {
|
||||||
return new Server(opts, requestListener);
|
return new Server(opts, requestListener);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTPS agents.
|
// HTTPS agents.
|
||||||
@ -130,7 +134,7 @@ function Agent(options) {
|
|||||||
if (!(this instanceof Agent))
|
if (!(this instanceof Agent))
|
||||||
return new Agent(options);
|
return new Agent(options);
|
||||||
|
|
||||||
http.Agent.call(this, options);
|
HttpAgent.call(this, options);
|
||||||
this.defaultPort = 443;
|
this.defaultPort = 443;
|
||||||
this.protocol = 'https:';
|
this.protocol = 'https:';
|
||||||
this.maxCachedSessions = this.options.maxCachedSessions;
|
this.maxCachedSessions = this.options.maxCachedSessions;
|
||||||
@ -142,11 +146,11 @@ function Agent(options) {
|
|||||||
list: []
|
list: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
inherits(Agent, http.Agent);
|
inherits(Agent, HttpAgent);
|
||||||
Agent.prototype.createConnection = createConnection;
|
Agent.prototype.createConnection = createConnection;
|
||||||
|
|
||||||
Agent.prototype.getName = function getName(options) {
|
Agent.prototype.getName = function getName(options) {
|
||||||
var name = http.Agent.prototype.getName.call(this, options);
|
var name = HttpAgent.prototype.getName.call(this, options);
|
||||||
|
|
||||||
name += ':';
|
name += ':';
|
||||||
if (options.ca)
|
if (options.ca)
|
||||||
@ -220,10 +224,7 @@ Agent.prototype._evictSession = function _evictSession(key) {
|
|||||||
|
|
||||||
const globalAgent = new Agent();
|
const globalAgent = new Agent();
|
||||||
|
|
||||||
exports.globalAgent = globalAgent;
|
function request(options, cb) {
|
||||||
exports.Agent = Agent;
|
|
||||||
|
|
||||||
exports.request = function request(options, cb) {
|
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = url.parse(options);
|
options = url.parse(options);
|
||||||
if (!options.hostname) {
|
if (!options.hostname) {
|
||||||
@ -237,11 +238,20 @@ exports.request = function request(options, cb) {
|
|||||||
options = util._extend({}, options);
|
options = util._extend({}, options);
|
||||||
}
|
}
|
||||||
options._defaultAgent = globalAgent;
|
options._defaultAgent = globalAgent;
|
||||||
return http.request(options, cb);
|
return new ClientRequest(options, cb);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get = function get(options, cb) {
|
function get(options, cb) {
|
||||||
var req = exports.request(options, cb);
|
const req = request(options, cb);
|
||||||
req.end();
|
req.end();
|
||||||
return req;
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Agent,
|
||||||
|
globalAgent,
|
||||||
|
Server,
|
||||||
|
createServer,
|
||||||
|
get,
|
||||||
|
request
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user