Skip to content

Commit 5118f31

Browse files
committed
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: nodejs#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>
1 parent 9ab6481 commit 5118f31

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

lib/https.js

+27-17
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ require('internal/util').assertCrypto();
2525

2626
const tls = require('tls');
2727
const url = require('url');
28-
const http = require('http');
2928
const util = require('util');
29+
const { Agent: HttpAgent } = require('_http_agent');
30+
const {
31+
Server: HttpServer,
32+
_connectionListener
33+
} = require('_http_server');
34+
const { ClientRequest } = require('_http_client');
3035
const { inherits } = util;
3136
const debug = util.debuglog('https');
3237
const { urlToOptions, searchParamsSymbol } = require('internal/url');
@@ -52,7 +57,7 @@ function Server(opts, requestListener) {
5257
opts.ALPNProtocols = ['http/1.1'];
5358
}
5459

55-
tls.Server.call(this, opts, http._connectionListener);
60+
tls.Server.call(this, opts, _connectionListener);
5661

5762
this.httpAllowHalfOpen = false;
5863

@@ -69,13 +74,12 @@ function Server(opts, requestListener) {
6974
this.keepAliveTimeout = 5000;
7075
}
7176
inherits(Server, tls.Server);
72-
exports.Server = Server;
7377

74-
Server.prototype.setTimeout = http.Server.prototype.setTimeout;
78+
Server.prototype.setTimeout = HttpServer.prototype.setTimeout;
7579

76-
exports.createServer = function createServer(opts, requestListener) {
80+
function createServer(opts, requestListener) {
7781
return new Server(opts, requestListener);
78-
};
82+
}
7983

8084

8185
// HTTPS agents.
@@ -130,7 +134,7 @@ function Agent(options) {
130134
if (!(this instanceof Agent))
131135
return new Agent(options);
132136

133-
http.Agent.call(this, options);
137+
HttpAgent.call(this, options);
134138
this.defaultPort = 443;
135139
this.protocol = 'https:';
136140
this.maxCachedSessions = this.options.maxCachedSessions;
@@ -142,11 +146,11 @@ function Agent(options) {
142146
list: []
143147
};
144148
}
145-
inherits(Agent, http.Agent);
149+
inherits(Agent, HttpAgent);
146150
Agent.prototype.createConnection = createConnection;
147151

148152
Agent.prototype.getName = function getName(options) {
149-
var name = http.Agent.prototype.getName.call(this, options);
153+
var name = HttpAgent.prototype.getName.call(this, options);
150154

151155
name += ':';
152156
if (options.ca)
@@ -220,10 +224,7 @@ Agent.prototype._evictSession = function _evictSession(key) {
220224

221225
const globalAgent = new Agent();
222226

223-
exports.globalAgent = globalAgent;
224-
exports.Agent = Agent;
225-
226-
exports.request = function request(options, cb) {
227+
function request(options, cb) {
227228
if (typeof options === 'string') {
228229
options = url.parse(options);
229230
if (!options.hostname) {
@@ -237,11 +238,20 @@ exports.request = function request(options, cb) {
237238
options = util._extend({}, options);
238239
}
239240
options._defaultAgent = globalAgent;
240-
return http.request(options, cb);
241-
};
241+
return new ClientRequest(options, cb);
242+
}
242243

243-
exports.get = function get(options, cb) {
244-
var req = exports.request(options, cb);
244+
function get(options, cb) {
245+
const req = request(options, cb);
245246
req.end();
246247
return req;
248+
}
249+
250+
module.exports = {
251+
Agent,
252+
globalAgent,
253+
Server,
254+
createServer,
255+
get,
256+
request
247257
};

0 commit comments

Comments
 (0)