Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 754df71

Browse filesBrowse files
benglgibfahn
authored andcommitted
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: #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 a763fcd commit 754df71
Copy full SHA for 754df71

File tree

Expand file treeCollapse file tree

1 file changed

+28
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-18
lines changed
Open diff view settings
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+28-18Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ 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');
30-
const inherits = util.inherits;
29+
const { Agent: HttpAgent } = require('_http_agent');
30+
const {
31+
Server: HttpServer,
32+
_connectionListener
33+
} = require('_http_server');
34+
const { ClientRequest } = require('_http_client');
35+
const { inherits } = util;
3136
const debug = util.debuglog('https');
3237
const { urlToOptions, searchParamsSymbol } = require('internal/url');
3338

@@ -51,7 +56,7 @@ function Server(opts, requestListener) {
5156
opts.ALPNProtocols = ['http/1.1'];
5257
}
5358

54-
tls.Server.call(this, opts, http._connectionListener);
59+
tls.Server.call(this, opts, _connectionListener);
5560

5661
this.httpAllowHalfOpen = false;
5762

@@ -68,13 +73,12 @@ function Server(opts, requestListener) {
6873
this.keepAliveTimeout = 5000;
6974
}
7075
inherits(Server, tls.Server);
71-
exports.Server = Server;
7276

73-
Server.prototype.setTimeout = http.Server.prototype.setTimeout;
77+
Server.prototype.setTimeout = HttpServer.prototype.setTimeout;
7478

75-
exports.createServer = function createServer(opts, requestListener) {
79+
function createServer(opts, requestListener) {
7680
return new Server(opts, requestListener);
77-
};
81+
}
7882

7983

8084
// HTTPS agents.
@@ -129,7 +133,7 @@ function Agent(options) {
129133
if (!(this instanceof Agent))
130134
return new Agent(options);
131135

132-
http.Agent.call(this, options);
136+
HttpAgent.call(this, options);
133137
this.defaultPort = 443;
134138
this.protocol = 'https:';
135139
this.maxCachedSessions = this.options.maxCachedSessions;
@@ -141,11 +145,11 @@ function Agent(options) {
141145
list: []
142146
};
143147
}
144-
inherits(Agent, http.Agent);
148+
inherits(Agent, HttpAgent);
145149
Agent.prototype.createConnection = createConnection;
146150

147151
Agent.prototype.getName = function getName(options) {
148-
var name = http.Agent.prototype.getName.call(this, options);
152+
var name = HttpAgent.prototype.getName.call(this, options);
149153

150154
name += ':';
151155
if (options.ca)
@@ -219,10 +223,7 @@ Agent.prototype._evictSession = function _evictSession(key) {
219223

220224
const globalAgent = new Agent();
221225

222-
exports.globalAgent = globalAgent;
223-
exports.Agent = Agent;
224-
225-
exports.request = function request(options, cb) {
226+
function request(options, cb) {
226227
if (typeof options === 'string') {
227228
options = url.parse(options);
228229
if (!options.hostname) {
@@ -236,11 +237,20 @@ exports.request = function request(options, cb) {
236237
options = util._extend({}, options);
237238
}
238239
options._defaultAgent = globalAgent;
239-
return http.request(options, cb);
240-
};
240+
return new ClientRequest(options, cb);
241+
}
241242

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.